[PATCH] [media] tda18212: fix use-after-free in tda18212_remove()

2017-12-15 Thread Daniel Scheller
From: Daniel Scheller 

When the driver gets unloaded via it's tda18212_remove() function, all
frontend structures may already have been freed as controlling/bridge
drivers already used dvb_frontend_detach() in their teardown process.
Since __dvb_frontend_free now releases and clears all structures, the
memset and the NULL assignment in tda18212_remove() leads to this KASAN
report (invoked via ddbridge, which does dvb_frontend_detach() first,
followed by i2c_unregister_device()):

  [  154.028353] 
==
  [  154.028396] BUG: KASAN: use-after-free in tda18212_remove+0x5c/0xb0 
[tda18212]
  [  154.028415] Write of size 288 at addr 880108b554d8 by task rmmod/285

  [  154.028442] CPU: 0 PID: 285 Comm: rmmod Tainted: G C   
4.15.0-rc1-13682-g1363f325bc44 #1
  [  154.028444] Hardware name: Gigabyte Technology Co., Ltd. P35-DS3/P35-DS3, 
BIOS F3 06/11/2007
  [  154.028445] Call Trace:
  [  154.028452]  dump_stack+0x46/0x61
  [  154.028458]  print_address_description+0x79/0x270
  [  154.028462]  ? tda18212_remove+0x5c/0xb0 [tda18212]
  [  154.028465]  kasan_report+0x229/0x340
  [  154.028468]  memset+0x1f/0x40
  [  154.028472]  tda18212_remove+0x5c/0xb0 [tda18212]
  [  154.028476]  i2c_device_remove+0x97/0xe0
  [  154.028481]  device_release_driver_internal+0x267/0x510
  [  154.028484]  bus_remove_device+0x296/0x470
  [  154.028486]  device_del+0x35c/0x890
  [  154.028489]  ? __device_links_no_driver+0x1c0/0x1c0
  [  154.028493]  ? cxd2841er_get_algo+0x10/0x10 [cxd2841er]
  [  154.028497]  ? cxd2841er_get_algo+0x10/0x10 [cxd2841er]
  [  154.028500]  ? __module_text_address+0xe/0x140
  [  154.028503]  device_unregister+0x9/0x20
  [  154.028509]  dvb_input_detach.isra.24+0x286/0x480 [ddbridge]
  [  154.028514]  ddb_ports_detach+0x176/0x630 [ddbridge]
  [  154.028519]  ddb_remove+0x3c/0xb0 [ddbridge]
  [  154.028523]  pci_device_remove+0x93/0x1d0
  [  154.028526]  device_release_driver_internal+0x267/0x510
  [  154.028529]  driver_detach+0xb9/0x1b0
  [  154.028532]  bus_remove_driver+0xd0/0x1f0
  [  154.028536]  pci_unregister_driver+0x25/0x210
  [  154.028541]  module_exit_ddbridge+0xc/0x45 [ddbridge]
  [  154.028544]  SyS_delete_module+0x314/0x440
  [  154.028546]  ? free_module+0x5b0/0x5b0
  [  154.028550]  ? exit_to_usermode_loop+0xa9/0xc0
  [  154.028552]  ? free_module+0x5b0/0x5b0
  [  154.028554]  do_syscall_64+0x179/0x4c0
  [  154.028557]  ? do_page_fault+0x1b/0x60
  [  154.028560]  entry_SYSCALL64_slow_path+0x25/0x25
  [  154.028563] RIP: 0033:0x7f6c40930de7
  [  154.028565] RSP: 002b:7ffc060d6ab8 EFLAGS: 0206 ORIG_RAX: 
00b0
  [  154.028569] RAX: ffda RBX:  RCX: 
7f6c40930de7
  [  154.028571] RDX: 000a RSI: 0800 RDI: 
02053268
  [  154.028573] RBP: 02053200 R08:  R09: 
1999
  [  154.028574] R10: 0891 R11: 0206 R12: 
7ffc060d74ef
  [  154.028576] R13:  R14: 02053200 R15: 
02052010

  [  154.028588] Allocated by task 164:
  [  154.028603]  cxd2841er_attach+0xc3/0x7f0 [cxd2841er]
  [  154.028608]  demod_attach_cxd28xx+0x14c/0x3f0 [ddbridge]
  [  154.028612]  dvb_input_attach+0x671/0x1e20 [ddbridge]
  [  154.028616]  ddb_ports_attach+0x453/0xd00 [ddbridge]
  [  154.028620]  ddb_init+0x4b3/0xa30 [ddbridge]
  [  154.028624]  ddb_probe+0xa51/0xfe0 [ddbridge]
  [  154.028627]  pci_device_probe+0x279/0x480
  [  154.028630]  driver_probe_device+0x46f/0x7a0
  [  154.028632]  __driver_attach+0x133/0x170
  [  154.028634]  bus_for_each_dev+0x10a/0x190
  [  154.028637]  bus_add_driver+0x2a3/0x5a0
  [  154.028639]  driver_register+0x182/0x3a0
  [  154.028641]  0xa016808f
  [  154.028643]  do_one_initcall+0x77/0x1d0
  [  154.028646]  do_init_module+0x1c2/0x548
  [  154.028648]  load_module+0x5e61/0x8df0
  [  154.028650]  SyS_finit_module+0x142/0x150
  [  154.028652]  do_syscall_64+0x179/0x4c0
  [  154.028654]  return_from_SYSCALL_64+0x0/0x65

  [  154.028664] Freed by task 285:
  [  154.028676]  kfree+0x6c/0xa0
  [  154.028682]  __dvb_frontend_free+0x81/0xb0 [dvb_core]
  [  154.028687]  dvb_input_detach.isra.24+0x17c/0x480 [ddbridge]
  [  154.028691]  ddb_ports_detach+0x176/0x630 [ddbridge]
  [  154.028695]  ddb_remove+0x3c/0xb0 [ddbridge]
  [  154.028697]  pci_device_remove+0x93/0x1d0
  [  154.028700]  device_release_driver_internal+0x267/0x510
  [  154.028702]  driver_detach+0xb9/0x1b0
  [  154.028705]  bus_remove_driver+0xd0/0x1f0
  [  154.028707]  pci_unregister_driver+0x25/0x210
  [  154.028711]  module_exit_ddbridge+0xc/0x45 [ddbridge]
  [  154.028714]  SyS_delete_module+0x314/0x440
  [  154.028716]  do_syscall_64+0x179/0x4c0
  [  154.028718]  return_from_SYSCALL_64+0x0/0x65

  [  154.028729] The buggy address belongs to the object at 880108b55340
  which belongs to the cache kmalloc-2048 of size 2048
  [  154.028755] The buggy ad

Re: [PATCH] [media] tda18212: fix use-after-free in tda18212_remove()

2017-12-15 Thread Daniel Scheller
Hi,

On Fri, 15 Dec 2017 19:30:18 +0200
Antti Palosaari  wrote:

Thanks for your reply.

> Hello
> I think shared frontend structure, which is owned by demod driver, 
> should be there and valid on time tuner driver is removed. And thus 
> should not happen. Did you make driver unload on different order eg.
> not just reverse order than driver load?
> 
> IMHO these should go always
> 
> on load:
> 1) load demod driver (which makes shared frontend structure where
> also some tuner driver data lives)
> 2) load tuner driver
> 3) register frontend
> 
> on unload
> 1) unregister frontend
> 2) remove tuner driver
> 3) remove demod driver (frees shared data)

In ddbridge, we do (like in usb/em28xx and platform/sti/c8sectpfe, both
also use some demod+tda18212 combo):

dvb_unregister_frontend();
dvb_frontend_detach();
module_put(tda18212client->...owner);
i2c_unregister_device(tda18212client);

fe_detach() clears out the frontend references and frees/invalidates
the allocated resources. tuner_ops obviously isn't there then anymore.

The two mentioned drivers will very likely yield the same (or
similar) KASAN report. em28xx was even changed lately to do the teardown
the way ddbridge does in 910b0797fa9e8 ([1], cc'ing Matthias
here).

With that commit in mind I'm a bit unsure on what is correct or not.
OTOH, as dvb_frontend_detach() cleans up everything, IMHO there's no
need for the tuner driver to try to clean up further.

Please advise.

[1] https://git.linuxtv.org/media_tree.git/commit/?id=910b0797fa9e8.

Best regards,
Daniel

> On 12/15/2017 06:43 PM, Daniel Scheller wrote:
> > From: Daniel Scheller 
> > 
> > When the driver gets unloaded via it's tda18212_remove() function,
> > all frontend structures may already have been freed as
> > controlling/bridge drivers already used dvb_frontend_detach() in
> > their teardown process. Since __dvb_frontend_free now releases and
> > clears all structures, the memset and the NULL assignment in
> > tda18212_remove() leads to this KASAN report (invoked via ddbridge,
> > which does dvb_frontend_detach() first, followed by
> > i2c_unregister_device()):
> > 
> >[  154.028353]
> > ==
> > [  154.028396] BUG: KASAN: use-after-free in
> > tda18212_remove+0x5c/0xb0 [tda18212] [  154.028415] Write of size
> > 288 at addr 880108b554d8 by task rmmod/285
> > 
> >[  154.028442] CPU: 0 PID: 285 Comm: rmmod Tainted: G
> > C   4.15.0-rc1-13682-g1363f325bc44 #1 [  154.028444] Hardware
> > name: Gigabyte Technology Co., Ltd. P35-DS3/P35-DS3, BIOS F3
> > 06/11/2007 [  154.028445] Call Trace: [  154.028452]
> > dump_stack+0x46/0x61 [  154.028458]
> > print_address_description+0x79/0x270 [  154.028462]  ?
> > tda18212_remove+0x5c/0xb0 [tda18212] [  154.028465]
> > kasan_report+0x229/0x340 [  154.028468]  memset+0x1f/0x40
> >[  154.028472]  tda18212_remove+0x5c/0xb0 [tda18212]
> >[  154.028476]  i2c_device_remove+0x97/0xe0
> >[  154.028481]  device_release_driver_internal+0x267/0x510
> >[  154.028484]  bus_remove_device+0x296/0x470
> >[  154.028486]  device_del+0x35c/0x890
> >[  154.028489]  ? __device_links_no_driver+0x1c0/0x1c0
> >[  154.028493]  ? cxd2841er_get_algo+0x10/0x10 [cxd2841er]
> >[  154.028497]  ? cxd2841er_get_algo+0x10/0x10 [cxd2841er]
> >[  154.028500]  ? __module_text_address+0xe/0x140
> >[  154.028503]  device_unregister+0x9/0x20
> >[  154.028509]  dvb_input_detach.isra.24+0x286/0x480 [ddbridge]
> >[  154.028514]  ddb_ports_detach+0x176/0x630 [ddbridge]
> >[  154.028519]  ddb_remove+0x3c/0xb0 [ddbridge]
> >[  154.028523]  pci_device_remove+0x93/0x1d0
> >[  154.028526]  device_release_driver_internal+0x267/0x510
> >[  154.028529]  driver_detach+0xb9/0x1b0
> >[  154.028532]  bus_remove_driver+0xd0/0x1f0
> >[  154.028536]  pci_unregister_driver+0x25/0x210
> >[  154.028541]  module_exit_ddbridge+0xc/0x45 [ddbridge]
> >[  154.028544]  SyS_delete_module+0x314/0x440
> >[  154.028546]  ? free_module+0x5b0/0x5b0
> >[  154.028550]  ? exit_to_usermode_loop+0xa9/0xc0
> >[  154.028552]  ? free_module+0x5b0/0x5b0
> >[  154.028554]  do_syscall_64+0x179/0x4c0
> >[  154.028557]  ? do_page_fault+0x1b/0x60
> >[  154.028560]  entry_SYSCALL64_slow_path+0x25/0x25
> >[  154.028563] RIP: 0033:0x7f6c40930de7
> >[  154.028565] RSP: 002b:7ffc060d6ab8 EFLAGS: 0206
> > ORIG_RAX: 00b0 [  154.028569] RAX: ffda
> > RBX:  RCX: 7f6c40930de7 [  154.028571] RDX:
>

Re: [PATCH] [media] tda18212: fix use-after-free in tda18212_remove()

2017-12-15 Thread Daniel Scheller
On Fri, 15 Dec 2017 20:12:18 +0200
Antti Palosaari  wrote:

> On 12/15/2017 08:00 PM, Daniel Scheller wrote:
> > Hi,
> > 
> > On Fri, 15 Dec 2017 19:30:18 +0200
> > Antti Palosaari  wrote:
> > 
> > Thanks for your reply.
> >   
> >> Hello
> >> I think shared frontend structure, which is owned by demod driver,
> >> should be there and valid on time tuner driver is removed. And thus
> >> should not happen. Did you make driver unload on different order
> >> eg. not just reverse order than driver load?
> >>
> >> IMHO these should go always
> >>
> >> on load:
> >> 1) load demod driver (which makes shared frontend structure where
> >> also some tuner driver data lives)
> >> 2) load tuner driver
> >> 3) register frontend
> >>
> >> on unload
> >> 1) unregister frontend
> >> 2) remove tuner driver
> >> 3) remove demod driver (frees shared data)  
> > 
> > In ddbridge, we do (like in usb/em28xx and platform/sti/c8sectpfe,
> > both also use some demod+tda18212 combo):
> > 
> > dvb_unregister_frontend();
> > dvb_frontend_detach();
> > module_put(tda18212client->...owner);
> > i2c_unregister_device(tda18212client);
> > 
> > fe_detach() clears out the frontend references and frees/invalidates
> > the allocated resources. tuner_ops obviously isn't there then
> > anymore.  
> 
> yeah, but that's even ideally wrong. frontend design currently relies
> to shared data which is owned by demod driver and thus it should be
> last thing to be removed. Sure change like you did prevents issue,
> but logically it is still wrong and may not work on some other case.
> 
> > 
> > The two mentioned drivers will very likely yield the same (or
> > similar) KASAN report. em28xx was even changed lately to do the
> > teardown the way ddbridge does in 910b0797fa9e8 ([1], cc'ing
> > Matthias here).
> > 
> > With that commit in mind I'm a bit unsure on what is correct or not.
> > OTOH, as dvb_frontend_detach() cleans up everything, IMHO there's no
> > need for the tuner driver to try to clean up further.
> > 
> > Please advise.
> > 
> > [1]
> > https://git.linuxtv.org/media_tree.git/commit/?id=910b0797fa9e8.  
> 
> em28xx does it currently just correct.
> 1) unregister frontend

Note that this is a call to em28xx_unregister_dvb(), which in turn does
dvb_unregister_frontend() and then dvb_frontend_detach() (at this
stage, fe resources are gone).

> 2) remove I2C SEC
> 3) remove I2C tuner
> 4) remove I2C demod (frees shared frontend data)

Yes, but ie. EM2874_BOARD_KWORLD_UB435Q_V3 is a combination of a
"legacy" demod frontend - lgdt3305 actually - plus the tda18212
i2cclient (just like in ddb with stv0367+tda18212 or
cxd2841er+tda18212), I'm sure this will yield the same report.

Maybe another approach: Implement the tuner_ops.release callback, and
then move the memset+NULL assignment right there (instead of just
removing it), but this likely will cause issues when the i2c client is
removed before detach if we don't keep track of this ie somewhere in
tda18212_dev (new state var - if _remove is called, check if the tuner
was released, and if not, call release (memset/set NULL), then
free). Still with the two other drivers in mind though. If they're
wrong aswell, I'll rather fix up ddbridge of course.

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


Re: [PATCH] [media] tda18212: fix use-after-free in tda18212_remove()

2017-12-15 Thread Daniel Scheller
On Fri, 15 Dec 2017 21:06:32 +0200
Antti Palosaari  wrote:

> On 12/15/2017 08:40 PM, Daniel Scheller wrote:
> > On Fri, 15 Dec 2017 20:12:18 +0200
> > Antti Palosaari  wrote:
> >>
> >> em28xx does it currently just correct.
> >> 1) unregister frontend  
> > 
> > Note that this is a call to em28xx_unregister_dvb(), which in turn
> > does dvb_unregister_frontend() and then dvb_frontend_detach() (at
> > this stage, fe resources are gone).
> >   
> >> 2) remove I2C SEC
> >> 3) remove I2C tuner
> >> 4) remove I2C demod (frees shared frontend data)  
> > 
> > Yes, but ie. EM2874_BOARD_KWORLD_UB435Q_V3 is a combination of a
> > "legacy" demod frontend - lgdt3305 actually - plus the tda18212
> > i2cclient (just like in ddb with stv0367+tda18212 or
> > cxd2841er+tda18212), I'm sure this will yield the same report.
> > 
> > Maybe another approach: Implement the tuner_ops.release callback,
> > and then move the memset+NULL assignment right there (instead of
> > just removing it), but this likely will cause issues when the i2c
> > client is removed before detach if we don't keep track of this ie
> > somewhere in tda18212_dev (new state var - if _remove is called,
> > check if the tuner was released, and if not, call release
> > (memset/set NULL), then free). Still with the two other drivers in
> > mind though. If they're wrong aswell, I'll rather fix up ddbridge
> > of course.  
> 
> Whole memset thing could be removed from tda18212, there is something 
> likely wrong if those are needed. But it is another issue.

On a side note: After some few more glances, there are many other
drivers in media/tuners/ that would require such treatment (tbh I just
peeked into tda18212 when investigating the KASAN report).

> Your main issue is somehow to get order of demod/tuner destroy
> correct. I don't even like idea whole shared frontend data is owned
> by the demod driver instance, but currently it is there and due to
> that this should be released lastly. General design goal is also do
> things like register things in order and unregister just
> reverse-order.

Fully agreeing on the last bit. I'll see how to improve on this in
ddbridge. Yet, very likely other drivers (and I have a feeling there
are quite some) with this issue (wrong teardown order) remain.

It might indeed be better if in frontend_ops, tuner_ops would be a ptr
to some struct that is managed by the tuner driver itself, that would
save from such issues.

Anyway, thank you very much for your input! (and apologies for any
noise or nonsense)

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


[PATCH 8/8] [media] ddbridge: improve ddb_ports_attach() failure handling

2017-12-17 Thread Daniel Scheller
From: Daniel Scheller 

As all error handling improved quite a bit, don't stop attaching frontends
if one of them failed, since - if other tuner modules are connected to
the PCIe bridge - other hardware may just work, so don't break on a single
port failure, but rather initialise as much as possible. Ie. if there are
issues with a C2T2-equipped PCIe bridge card which has additional DuoFlex
modules connected and the bridge generally works, the DuoFlex tuners can
still work fine.

If all ports failed to initialise where connected hardware was detected on
at first, return -ENODEV though to cause this PCI device to fail and free
all allocated resources. In any case, leave a kernel log warning (or
error, even) if things went wrong.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 26 +++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 940371067346..c7d923e0e21a 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1964,7 +1964,7 @@ static int ddb_port_attach(struct ddb_port *port)
 
 int ddb_ports_attach(struct ddb *dev)
 {
-   int i, ret = 0;
+   int i, numports, err_ports = 0, ret = 0;
struct ddb_port *port;
 
if (dev->port_num) {
@@ -1974,11 +1974,31 @@ int ddb_ports_attach(struct ddb *dev)
return ret;
}
}
+
+   numports = dev->port_num;
+
for (i = 0; i < dev->port_num; i++) {
port = &dev->port[i];
-   ret = ddb_port_attach(port);
+   if (port->class != DDB_PORT_NONE) {
+   ret = ddb_port_attach(port);
+   if (ret)
+   err_ports++;
+   } else {
+   numports--;
+   }
}
-   return ret;
+
+   if (err_ports) {
+   if (err_ports == numports) {
+   dev_err(dev->dev, "All connected ports failed to 
initialise!\n");
+   return -ENODEV;
+   }
+
+   dev_warn(dev->dev, "%d of %d connected ports failed to 
initialise!\n",
+err_ports, numports);
+   }
+
+   return 0;
 }
 
 void ddb_ports_detach(struct ddb *dev)
-- 
2.13.6



[PATCH 0/8] ddbridge improvements and cleanups

2017-12-17 Thread Daniel Scheller
From: Daniel Scheller 

This series improves on a few things in ddbridge:

* Fix up a KASAN report which pops up with all TDA18212-equipped hardware
  by changing the order of all frontend driver teardown. This was
  originally thought to be a problem of the tda18212 driver, see
  https://patchwork.linuxtv.org/patch/45992/ (though other drivers with
  that problem may remain).
* Fix up CI resources cleanup handling, and further cosmetics and code
  move, all CI related
* Frontend cleanup improvements when handling errors (ie. when on one
  port the device initialisation fails). Whenever a tuner module fails
  now, everything should be cleaned up properly (and early) now, while
  all other (working) tuners are being usable. Proper errors are printed
  to the kernel log about this.

Mauro, I'm pretty sure you like this overall approach better, compared
to https://patchwork.linuxtv.org/patch/45810/ :-) In fact, I picked up
your idea of counting ports and act accordingly. Partial hardware setup
now starts up all working parts properly, while releasing resources
early when the nonworking parts are handled. If no ports could be started
at all, the driver instance will fail gracefully and report this to
upper layers.

I verified this by simply removing tda18212.ko with this DD setup:

* CineCTv6 bridge card (stv0367+tda18212 soldered on it, handled as
  port 0), one DuoFlex C2T2 connected to port 1 (cxd2841er+tda18212)
* Octopus CI Duo, one DuoFlex C2T2I (cxd2841er+tda18212) connected to
  port 1, one SingleCI module (cxd2099) connected to port 2

Upon modprobe ddbridge, the CTv6 will completely fail due to the tuner
driver not initialising (it's not there, actually). The OctoCIDUO
will fail on the C2T2I Flex, but starts up the CI hardware, registers
it's en50221 device nodes and things work fine with it. Unload cleans
up everything, no leaked usecounts, no KASAN complaints. Putting back
tda18212.ko, modprobe ddbridge - registers everything. Unload cleans
up everything properly aswell.

Not entirely sure, but patch 1 might be something for stable (ie. 4.14).

Daniel Scheller (8):
  [media] ddbridge: unregister I2C tuner client before detaching fe's
  [media] ddbridge: fix resources cleanup for CI hardware
  [media] ddbridge: deduplicate calls to dvb_ca_en50221_init()
  [media] ddbridge: move CI detach code to ddbridge-ci.c
  [media] ddbridge: completely tear down input resources on failure
  [media] ddbridge: fix deinit order in case of failure in ddb_init()
  [media] ddbridge: detach first input if the second one failed to init
  [media] ddbridge: improve ddb_ports_attach() failure handling

 drivers/media/pci/ddbridge/ddbridge-ci.c   |  17 +++--
 drivers/media/pci/ddbridge/ddbridge-ci.h   |   1 +
 drivers/media/pci/ddbridge/ddbridge-core.c | 108 ++---
 3 files changed, 81 insertions(+), 45 deletions(-)

-- 
2.13.6



[PATCH 1/8] [media] ddbridge: unregister I2C tuner client before detaching fe's

2017-12-17 Thread Daniel Scheller
From: Daniel Scheller 

Currently, rmmod ddbridge on a KASAN enabled kernel yields this report
for hardware that utilises the tda18212 tuner driver:

  [   50.355229] 
==
  [   50.355271] BUG: KASAN: use-after-free in tda18212_remove+0x5c/0xb0 
[tda18212]
  [   50.355290] Write of size 288 at addr 8800c235cf18 by task rmmod/285

  [   50.355316] CPU: 1 PID: 285 Comm: rmmod Not tainted 
4.15.0-rc1-13744-g352a86ad536f #11
  [   50.355318] Hardware name: Gigabyte Technology Co., Ltd. P35-DS3/P35-DS3, 
BIOS F3 06/11/2007
  [   50.355319] Call Trace:
  [   50.355326]  dump_stack+0x46/0x61
  [   50.355332]  print_address_description+0x79/0x270
  [   50.355336]  ? tda18212_remove+0x5c/0xb0 [tda18212]
  [   50.355339]  kasan_report+0x229/0x340
  [   50.355342]  memset+0x1f/0x40
  [   50.355345]  tda18212_remove+0x5c/0xb0 [tda18212]
  [   50.355350]  i2c_device_remove+0x97/0xe0
  [   50.355355]  device_release_driver_internal+0x267/0x510
  [   50.355358]  bus_remove_device+0x296/0x470
  [   50.355360]  device_del+0x35c/0x890
  [   50.355363]  ? __device_links_no_driver+0x1c0/0x1c0
  [   50.355367]  ? cxd2841er_get_algo+0x10/0x10 [cxd2841er]
  [   50.355371]  ? cxd2841er_get_algo+0x10/0x10 [cxd2841er]
  [   50.355374]  ? __module_text_address+0xe/0x140
  [   50.355377]  device_unregister+0x9/0x20
  [   50.355382]  dvb_input_detach.isra.24+0x286/0x480 [ddbridge]
  [   50.355388]  ddb_ports_detach+0x15f/0x4f0 [ddbridge]
  [   50.355393]  ddb_remove+0x3c/0xb0 [ddbridge]
  [   50.355397]  pci_device_remove+0x93/0x1d0
  [   50.355400]  device_release_driver_internal+0x267/0x510
  [   50.355403]  driver_detach+0xb9/0x1b0
  [   50.355406]  bus_remove_driver+0xd0/0x1f0
  [   50.355410]  pci_unregister_driver+0x25/0x210
  [   50.355415]  module_exit_ddbridge+0xc/0x45 [ddbridge]
  [   50.355418]  SyS_delete_module+0x314/0x440
  [   50.355420]  ? free_module+0x5b0/0x5b0
  [   50.355423]  ? exit_to_usermode_loop+0xa9/0xc0
  [   50.355425]  ? free_module+0x5b0/0x5b0
  [   50.355428]  do_syscall_64+0x179/0x4c0
  [   50.355432]  ? do_page_fault+0x1b/0x60
  [   50.355435]  entry_SYSCALL64_slow_path+0x25/0x25
  [   50.355438] RIP: 0033:0x7fe65d08ade7
  [   50.355439] RSP: 002b:7fff5a6a09a8 EFLAGS: 0202 ORIG_RAX: 
00b0
  [   50.355443] RAX: ffda RBX:  RCX: 
7fe65d08ade7
  [   50.355445] RDX: 000a RSI: 0800 RDI: 
00f4e268
  [   50.355447] RBP: 00f4e200 R08:  R09: 
1999
  [   50.355449] R10: 0891 R11: 0202 R12: 
7fff5a6a14ef
  [   50.355451] R13:  R14: 00f4e200 R15: 
00f4d010

  [   50.355462] Allocated by task 164:
  [   50.355477]  cxd2841er_attach+0xc3/0x7f0 [cxd2841er]
  [   50.355482]  demod_attach_cxd28xx+0x14c/0x3f0 [ddbridge]
  [   50.355486]  dvb_input_attach+0x671/0x1e20 [ddbridge]
  [   50.355490]  ddb_ports_attach+0x3d7/0xbf0 [ddbridge]
  [   50.355495]  ddb_init+0x4b3/0xa30 [ddbridge]
  [   50.355499]  ddb_probe+0xa51/0xfe0 [ddbridge]
  [   50.355501]  pci_device_probe+0x279/0x480
  [   50.355504]  driver_probe_device+0x46f/0x7a0
  [   50.355506]  __driver_attach+0x133/0x170
  [   50.355509]  bus_for_each_dev+0x10a/0x190
  [   50.355511]  bus_add_driver+0x2a3/0x5a0
  [   50.355513]  driver_register+0x182/0x3a0
  [   50.355516]  arc4_set_key+0x8f/0x2a0 [arc4]
  [   50.355518]  do_one_initcall+0x77/0x1d0
  [   50.355521]  do_init_module+0x1c2/0x548
  [   50.355523]  load_module+0x5e61/0x8df0
  [   50.355525]  SyS_finit_module+0x142/0x150
  [   50.355527]  do_syscall_64+0x179/0x4c0
  [   50.355529]  return_from_SYSCALL_64+0x0/0x65

  [   50.355539] Freed by task 285:
  [   50.31]  kfree+0x6c/0xa0
  [   50.38]  __dvb_frontend_free+0x81/0xb0 [dvb_core]
  [   50.355562]  dvb_input_detach.isra.24+0x17c/0x480 [ddbridge]
  [   50.355566]  ddb_ports_detach+0x15f/0x4f0 [ddbridge]
  [   50.355570]  ddb_remove+0x3c/0xb0 [ddbridge]
  [   50.355573]  pci_device_remove+0x93/0x1d0
  [   50.355576]  device_release_driver_internal+0x267/0x510
  [   50.355578]  driver_detach+0xb9/0x1b0
  [   50.355580]  bus_remove_driver+0xd0/0x1f0
  [   50.355583]  pci_unregister_driver+0x25/0x210
  [   50.355587]  module_exit_ddbridge+0xc/0x45 [ddbridge]
  [   50.355590]  SyS_delete_module+0x314/0x440
  [   50.355592]  do_syscall_64+0x179/0x4c0
  [   50.355594]  return_from_SYSCALL_64+0x0/0x65

  [   50.355604] The buggy address belongs to the object at 8800c235cd80
  which belongs to the cache kmalloc-2048 of size 2048
  [   50.355630] The buggy address is located 408 bytes inside of
  2048-byte region [8800c235cd80, 8800c235d580)
  [   50.355652] The buggy address belongs to the page:
  [   50.355666] page:ea0002a7bc20 count:1 mapcount:0 
mapping:8800c235c500 index:0x0 compound_mapcount: 0
  [   50.355688] flags: 0x40008100(slab|head

[PATCH 4/8] [media] ddbridge: move CI detach code to ddbridge-ci.c

2017-12-17 Thread Daniel Scheller
From: Daniel Scheller 

Move the CI teardown code to ddbridge-ci.c where everything else related
to CI hardware lives.

Cc: Ralph Metzler 
Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-ci.c   | 11 +++
 drivers/media/pci/ddbridge/ddbridge-ci.h   |  1 +
 drivers/media/pci/ddbridge/ddbridge-core.c |  8 +---
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-ci.c 
b/drivers/media/pci/ddbridge/ddbridge-ci.c
index 8dfbc3bbd86d..5828111487b0 100644
--- a/drivers/media/pci/ddbridge/ddbridge-ci.c
+++ b/drivers/media/pci/ddbridge/ddbridge-ci.c
@@ -346,3 +346,14 @@ int ddb_ci_attach(struct ddb_port *port, u32 bitrate)
dvb_ca_en50221_init(port->dvb[0].adap, port->en, 0, 1);
return 0;
 }
+
+void ddb_ci_detach(struct ddb_port *port)
+{
+   if (port->dvb[0].dev)
+   dvb_unregister_device(port->dvb[0].dev);
+   if (port->en) {
+   dvb_ca_en50221_release(port->en);
+   kfree(port->en->data);
+   port->en = NULL;
+   }
+}
diff --git a/drivers/media/pci/ddbridge/ddbridge-ci.h 
b/drivers/media/pci/ddbridge/ddbridge-ci.h
index 3a5d7ffab7b7..35a39182dd83 100644
--- a/drivers/media/pci/ddbridge/ddbridge-ci.h
+++ b/drivers/media/pci/ddbridge/ddbridge-ci.h
@@ -26,5 +26,6 @@
 
/**/
 
 int ddb_ci_attach(struct ddb_port *port, u32 bitrate);
+void ddb_ci_detach(struct ddb_port *port);
 
 #endif /* __DDBRIDGE_CI_H__ */
diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index a81125d492ff..c2f028152388 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1986,13 +1986,7 @@ void ddb_ports_detach(struct ddb *dev)
break;
case DDB_PORT_CI:
case DDB_PORT_LOOP:
-   if (port->dvb[0].dev)
-   dvb_unregister_device(port->dvb[0].dev);
-   if (port->en) {
-   dvb_ca_en50221_release(port->en);
-   kfree(port->en->data);
-   port->en = NULL;
-   }
+   ddb_ci_detach(port);
break;
}
}
-- 
2.13.6



[PATCH 2/8] [media] ddbridge: fix resources cleanup for CI hardware

2017-12-17 Thread Daniel Scheller
From: Daniel Scheller 

Do kfree() on port->en->data instead of port->en. port->en only holds a
ptr to a struct dvb_ca_en50221, which is a member either of a memalloc'ed
struct ddb_ci (DuoFlex CI, Octopus CI Duo) or a struct cxd (CXD2099AR
based Single Flex, allocated by the cxd2099 driver). port->en.data
though holds the ptr to the allocated memory, which must rather be
kfree()'d. Change this accordingly.

Cc: Ralph Metzler 
Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index eda004398316..a81125d492ff 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1990,7 +1990,7 @@ void ddb_ports_detach(struct ddb *dev)
dvb_unregister_device(port->dvb[0].dev);
if (port->en) {
dvb_ca_en50221_release(port->en);
-   kfree(port->en);
+   kfree(port->en->data);
port->en = NULL;
}
break;
-- 
2.13.6



[PATCH 6/8] [media] ddbridge: fix deinit order in case of failure in ddb_init()

2017-12-17 Thread Daniel Scheller
From: Daniel Scheller 

In ddb_init(), the deinitialization sequence isn't correct when handling
errors, and could even lead to a memleak depending on where things failed.
Fix the deinit order.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 07f3e37a0fca..548b7047ca09 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -3273,7 +3273,7 @@ int ddb_init(struct ddb *dev)
ddb_init_boards(dev);
 
if (ddb_i2c_init(dev) < 0)
-   goto fail;
+   goto fail1;
ddb_ports_init(dev);
if (ddb_buffers_alloc(dev) < 0) {
dev_info(dev->dev, "Could not allocate buffer memory\n");
@@ -3291,14 +3291,14 @@ int ddb_init(struct ddb *dev)
return 0;
 
 fail3:
-   ddb_ports_detach(dev);
dev_err(dev->dev, "fail3\n");
-   ddb_ports_release(dev);
+   ddb_ports_detach(dev);
+   ddb_buffers_free(dev);
 fail2:
dev_err(dev->dev, "fail2\n");
-   ddb_buffers_free(dev);
+   ddb_ports_release(dev);
ddb_i2c_release(dev);
-fail:
+fail1:
dev_err(dev->dev, "fail1\n");
return -1;
 }
-- 
2.13.6



[PATCH 5/8] [media] ddbridge: completely tear down input resources on failure

2017-12-17 Thread Daniel Scheller
From: Daniel Scheller 

In dvb_input_attach(), whenever a demod driver fails to initialise, or if
frontend registration fails, perform a full input/frontend teardown using
dvb_input_detach() (which can safely be done since the current init state
is tracked in the 'attached' struct member). Claimed resources thus are
freed which aren't needed when an input or a port is not functional.

While at it, in ddb_ports_detach(), detach the secondary input first. Also
increase the kernlog severity of TDA18212 errors and tuner failures in
general.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 46 ++
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index c2f028152388..07f3e37a0fca 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1032,7 +1032,7 @@ static int tuner_attach_tda18212(struct ddb_input *input, 
u32 porttype)
 
return 0;
 err:
-   dev_notice(dev, "TDA18212 tuner not found. Device is not fully 
operational.\n");
+   dev_err(dev, "TDA18212 tuner not found. Device is not fully 
operational.\n");
return -ENODEV;
 }
 
@@ -1425,7 +1425,7 @@ static int dvb_input_attach(struct ddb_input *input)
dvb->dmxdev.demux = &dvbdemux->dmx;
ret = dvb_dmxdev_init(&dvb->dmxdev, adap);
if (ret < 0)
-   return ret;
+   goto err_detach;
dvb->attached = 0x11;
 
dvb->mem_frontend.source = DMX_MEMORY_FE;
@@ -1434,12 +1434,12 @@ static int dvb_input_attach(struct ddb_input *input)
dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->hw_frontend);
ret = dvbdemux->dmx.connect_frontend(&dvbdemux->dmx, &dvb->hw_frontend);
if (ret < 0)
-   return ret;
+   goto err_detach;
dvb->attached = 0x12;
 
ret = dvb_net_init(adap, &dvb->dvbnet, dvb->dmxdev.demux);
if (ret < 0)
-   return ret;
+   goto err_detach;
dvb->attached = 0x20;
 
dvb->fe = NULL;
@@ -1447,47 +1447,47 @@ static int dvb_input_attach(struct ddb_input *input)
switch (port->type) {
case DDB_TUNER_MXL5XX:
if (ddb_fe_attach_mxl5xx(input) < 0)
-   return -ENODEV;
+   goto err_detach;
break;
case DDB_TUNER_DVBS_ST:
if (demod_attach_stv0900(input, 0) < 0)
-   return -ENODEV;
+   goto err_detach;
if (tuner_attach_stv6110(input, 0) < 0)
goto err_tuner;
break;
case DDB_TUNER_DVBS_ST_AA:
if (demod_attach_stv0900(input, 1) < 0)
-   return -ENODEV;
+   goto err_detach;
if (tuner_attach_stv6110(input, 1) < 0)
goto err_tuner;
break;
case DDB_TUNER_DVBS_STV0910:
if (demod_attach_stv0910(input, 0) < 0)
-   return -ENODEV;
+   goto err_detach;
if (tuner_attach_stv6111(input, 0) < 0)
goto err_tuner;
break;
case DDB_TUNER_DVBS_STV0910_PR:
if (demod_attach_stv0910(input, 1) < 0)
-   return -ENODEV;
+   goto err_detach;
if (tuner_attach_stv6111(input, 1) < 0)
goto err_tuner;
break;
case DDB_TUNER_DVBS_STV0910_P:
if (demod_attach_stv0910(input, 0) < 0)
-   return -ENODEV;
+   goto err_detach;
if (tuner_attach_stv6111(input, 1) < 0)
goto err_tuner;
break;
case DDB_TUNER_DVBCT_TR:
if (demod_attach_drxk(input) < 0)
-   return -ENODEV;
+   goto err_detach;
if (tuner_attach_tda18271(input) < 0)
goto err_tuner;
break;
case DDB_TUNER_DVBCT_ST:
if (demod_attach_stv0367(input) < 0)
-   return -ENODEV;
+   goto err_detach;
if (tuner_attach_tda18212(input, port->type) < 0)
goto err_tuner;
break;
@@ -1507,7 +1507,7 @@ static int dvb_input_attach(struct ddb_input *input)
else
par = 1;
if (demod_attach_cxd28xx(input, par, osc24) < 0)
-   return -ENODEV;
+   goto err_detach;
if (tuner_attach_tda18212(

[PATCH 3/8] [media] ddbridge: deduplicate calls to dvb_ca_en50221_init()

2017-12-17 Thread Daniel Scheller
From: Daniel Scheller 

All CI types do dvb_ca_en50221_init() with the same arguments. Move this
call after the switch-case to remove the repetition in every case block.

Cc: Ralph Metzler 
Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-ci.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-ci.c 
b/drivers/media/pci/ddbridge/ddbridge-ci.c
index a4fd747763a0..8dfbc3bbd86d 100644
--- a/drivers/media/pci/ddbridge/ddbridge-ci.c
+++ b/drivers/media/pci/ddbridge/ddbridge-ci.c
@@ -327,8 +327,6 @@ int ddb_ci_attach(struct ddb_port *port, u32 bitrate)
port->en = cxd2099_attach(&cxd_cfg, port, &port->i2c->adap);
if (!port->en)
return -ENODEV;
-   dvb_ca_en50221_init(port->dvb[0].adap,
-   port->en, 0, 1);
break;
 
case DDB_CI_EXTERNAL_XO2:
@@ -336,15 +334,15 @@ int ddb_ci_attach(struct ddb_port *port, u32 bitrate)
ci_xo2_attach(port);
if (!port->en)
return -ENODEV;
-   dvb_ca_en50221_init(port->dvb[0].adap, port->en, 0, 1);
break;
 
case DDB_CI_INTERNAL:
ci_attach(port);
if (!port->en)
return -ENODEV;
-   dvb_ca_en50221_init(port->dvb[0].adap, port->en, 0, 1);
break;
}
+
+   dvb_ca_en50221_init(port->dvb[0].adap, port->en, 0, 1);
return 0;
 }
-- 
2.13.6



[PATCH 7/8] [media] ddbridge: detach first input if the second one failed to init

2017-12-17 Thread Daniel Scheller
From: Daniel Scheller 

In ddb_ports_attach(), if the second input of a dual tuner failed to
initialise, the first one can be detached (and resources be freed) as
this will be counted as the whole port having failed to initialise,
thus the first one won't be used anyway.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 548b7047ca09..940371067346 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1935,8 +1935,10 @@ static int ddb_port_attach(struct ddb_port *port)
if (ret < 0)
break;
ret = dvb_input_attach(port->input[1]);
-   if (ret < 0)
+   if (ret < 0) {
+   dvb_input_detach(port->input[0]);
break;
+   }
port->input[0]->redi = port->input[0];
port->input[1]->redi = port->input[1];
break;
-- 
2.13.6



Re: [PATCH 0/8] ddbridge improvements and cleanups

2017-12-17 Thread Daniel Scheller
On Sun, 17 Dec 2017 16:40:41 +0100
Daniel Scheller  wrote:

> I verified this by simply removing tda18212.ko with this DD setup:

Sorry, I forgot to outline this: I also tested by removing stv0367.ko
and cxd2841er.ko of course, which resulted in partially working
hardware, either the cxd-based hardware or the stv-based one didn't
work, while everything else did. Unload worked cleanly, without leaving
any side effects.

All this worked without these patches before of course, but as they
touch the attach logic and make failure cleanup resources instantly
now, this required retesting.

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


[PATCH] [media] dvb-frontend/mxl5xx: add support for physical layer scrambling

2017-12-20 Thread Daniel Scheller
From: Daniel Scheller 

The MaxLinear MxL5xx has support for physical layer scrambling, which was
recently added to the DVB core via the new scrambling_sequence_index
property. Add required bits to the mxl5xx driver.

Picked up from dddvb master, commit 5c032058b9ba ("add support for PLS")
by Ralph Metzler , adapted to the different naming
of the pls property (pls vs. scrambling_sequence_index).

Cc: Ralph Metzler 
Signed-off-by: Daniel Scheller 
---
NB, I'm also prepping up another set of patches that enable the stv0910
driver to handle the recently added PLS support.

 drivers/media/dvb-frontends/mxl5xx.c | 34 +-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/mxl5xx.c 
b/drivers/media/dvb-frontends/mxl5xx.c
index 1ebc3830579f..05f27f51fd03 100644
--- a/drivers/media/dvb-frontends/mxl5xx.c
+++ b/drivers/media/dvb-frontends/mxl5xx.c
@@ -380,6 +380,38 @@ static int get_algo(struct dvb_frontend *fe)
return DVBFE_ALGO_HW;
 }
 
+static u32 gold2root(u32 gold)
+{
+   u32 x, g, tmp = gold;
+
+   if (tmp >= 0x3)
+   tmp = 0;
+   for (g = 0, x = 1; g < tmp; g++)
+   x = (((x ^ (x >> 7)) & 1) << 17) | (x >> 1);
+   return x;
+}
+
+static int cfg_scrambler(struct mxl *state, u32 gold)
+{
+   u32 root;
+   u8 buf[26] = {
+   MXL_HYDRA_PLID_CMD_WRITE, 24,
+   0, MXL_HYDRA_DEMOD_SCRAMBLE_CODE_CMD, 0, 0,
+   state->demod, 0, 0, 0,
+   0, 0, 0, 0, 0, 0, 0, 0,
+   0, 0, 0, 0, 1, 0, 0, 0,
+   };
+
+   root = gold2root(gold);
+
+   buf[25] = (root >> 24) & 0xff;
+   buf[24] = (root >> 16) & 0xff;
+   buf[23] = (root >> 8) & 0xff;
+   buf[22] = root & 0xff;
+
+   return send_command(state, sizeof(buf), buf);
+}
+
 static int cfg_demod_abort_tune(struct mxl *state)
 {
struct MXL_HYDRA_DEMOD_ABORT_TUNE_T abort_tune_cmd;
@@ -437,7 +469,7 @@ static int set_parameters(struct dvb_frontend *fe)
demod_chan_cfg.roll_off = MXL_HYDRA_ROLLOFF_AUTO;
demod_chan_cfg.modulation_scheme = MXL_HYDRA_MOD_AUTO;
demod_chan_cfg.pilots = MXL_HYDRA_PILOTS_AUTO;
-   /* cfg_scrambler(state); */
+   cfg_scrambler(state, p->scrambling_sequence_index);
break;
default:
return -EINVAL;
-- 
2.13.6



[PATCH 1/2] media: dvb_frontend: add FEC modes, S2X modulations and 64K transmission

2017-12-21 Thread Daniel Scheller
From: Daniel Scheller 

Add 1/4 and 1/3 FEC ratios, 64/128/256-APSK S2X modulations and 64K
transmission mode. Update relevant doc items aswell.

Signed-off-by: Daniel Scheller 
---
 Documentation/media/frontend.h.rst.exceptions |  6 ++
 include/uapi/linux/dvb/frontend.h | 13 +
 2 files changed, 19 insertions(+)

diff --git a/Documentation/media/frontend.h.rst.exceptions 
b/Documentation/media/frontend.h.rst.exceptions
index f7c4df620a52..ae1148be0a39 100644
--- a/Documentation/media/frontend.h.rst.exceptions
+++ b/Documentation/media/frontend.h.rst.exceptions
@@ -84,6 +84,9 @@ ignore symbol APSK_16
 ignore symbol APSK_32
 ignore symbol DQPSK
 ignore symbol QAM_4_NR
+ignore symbol APSK_64
+ignore symbol APSK_128
+ignore symbol APSK_256
 
 ignore symbol SEC_VOLTAGE_13
 ignore symbol SEC_VOLTAGE_18
@@ -117,6 +120,8 @@ ignore symbol FEC_AUTO
 ignore symbol FEC_3_5
 ignore symbol FEC_9_10
 ignore symbol FEC_2_5
+ignore symbol FEC_1_4
+ignore symbol FEC_1_3
 
 ignore symbol TRANSMISSION_MODE_AUTO
 ignore symbol TRANSMISSION_MODE_1K
@@ -129,6 +134,7 @@ ignore symbol TRANSMISSION_MODE_C1
 ignore symbol TRANSMISSION_MODE_C3780
 ignore symbol TRANSMISSION_MODE_2K
 ignore symbol TRANSMISSION_MODE_8K
+ignore symbol TRANSMISSION_MODE_64K
 
 ignore symbol GUARD_INTERVAL_AUTO
 ignore symbol GUARD_INTERVAL_1_128
diff --git a/include/uapi/linux/dvb/frontend.h 
b/include/uapi/linux/dvb/frontend.h
index 4f9b4551c534..227268a657cd 100644
--- a/include/uapi/linux/dvb/frontend.h
+++ b/include/uapi/linux/dvb/frontend.h
@@ -296,6 +296,8 @@ enum fe_spectral_inversion {
  * @FEC_3_5:  Forward Error Correction Code 3/5
  * @FEC_9_10: Forward Error Correction Code 9/10
  * @FEC_2_5:  Forward Error Correction Code 2/5
+ * @FEC_1_4:  Forward Error Correction Code 1/4
+ * @FEC_1_3:  Forward Error Correction Code 1/3
  *
  * Please note that not all FEC types are supported by a given standard.
  */
@@ -313,6 +315,8 @@ enum fe_code_rate {
FEC_3_5,
FEC_9_10,
FEC_2_5,
+   FEC_1_4,
+   FEC_1_3,
 };
 
 /**
@@ -331,6 +335,9 @@ enum fe_code_rate {
  * @APSK_32:   32-APSK modulation
  * @DQPSK: DQPSK modulation
  * @QAM_4_NR:  4-QAM-NR modulation
+ * @APSK_64:   64-APSK modulation
+ * @APSK_128:  128-APSK modulation
+ * @APSK_256:  256-APSK modulation
  *
  * Please note that not all modulations are supported by a given standard.
  *
@@ -350,6 +357,9 @@ enum fe_modulation {
APSK_32,
DQPSK,
QAM_4_NR,
+   APSK_64,
+   APSK_128,
+   APSK_256,
 };
 
 /**
@@ -374,6 +384,8 @@ enum fe_modulation {
  * Single Carrier (C=1) transmission mode (DTMB only)
  * @TRANSMISSION_MODE_C3780:
  * Multi Carrier (C=3780) transmission mode (DTMB only)
+ * @TRANSMISSION_MODE_64K:
+ * Transmission mode 64K
  *
  * Please note that not all transmission modes are supported by a given
  * standard.
@@ -388,6 +400,7 @@ enum fe_transmit_mode {
TRANSMISSION_MODE_32K,
TRANSMISSION_MODE_C1,
TRANSMISSION_MODE_C3780,
+   TRANSMISSION_MODE_64K,
 };
 
 /**
-- 
2.13.6



[PATCH 0/2] Add FEC rates, S2X modulations and 64K transmission

2017-12-21 Thread Daniel Scheller
From: Daniel Scheller 

As the DVB API is bumped to 5.11 for the next cycle.

dddvb brings a few additional FEC rates (1/4 and 1/3), 64/128/256APSK
modulations (DVB-S2X) and the 64K transmission mode. These two rather
trivial patches bring them to mainline, and puts these missing bits
into the stv0910's get_frontend() callback (FEC 1/4 and 1/3 are handled
throughout the rest of the demod driver already).

Let's have these enums as a part of DVB core 5.11.

Daniel Scheller (2):
  media: dvb_frontend: add FEC modes, S2X modulations and 64K
transmission
  media: dvb-frontends/stv0910: report FEC 1/4 and 1/3 in get_frontend()

 Documentation/media/frontend.h.rst.exceptions |  6 ++
 drivers/media/dvb-frontends/stv0910.c |  2 +-
 include/uapi/linux/dvb/frontend.h | 13 +
 3 files changed, 20 insertions(+), 1 deletion(-)

-- 
2.13.6



[PATCH 2/2] media: dvb-frontends/stv0910: report FEC 1/4 and 1/3 in get_frontend()

2017-12-21 Thread Daniel Scheller
From: Daniel Scheller 

The first two missing FECs in the modcod2fec fe_code_rate table were 1/4
and 1/3. Add them as they're now defined by the API.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0910.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index a8c99f41478b..7cf90d435083 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -1551,7 +1551,7 @@ static int get_frontend(struct dvb_frontend *fe,
APSK_32,
};
const enum fe_code_rate modcod2fec[0x20] = {
-   FEC_NONE, FEC_NONE, FEC_NONE, FEC_2_5,
+   FEC_NONE, FEC_1_4, FEC_1_3, FEC_2_5,
FEC_1_2, FEC_3_5, FEC_2_3, FEC_3_4,
FEC_4_5, FEC_5_6, FEC_8_9, FEC_9_10,
FEC_3_5, FEC_2_3, FEC_3_4, FEC_5_6,
-- 
2.13.6



[PATCH 3/4] [media] dvb-frontends/stv0910: field and register access helpers

2017-12-26 Thread Daniel Scheller
From: Daniel Scheller 

Add a write_field() function that acts as helper to update specific bits
specified in the field defines (FSTV0910_*) in stv0910_regs.h, which was
recently updated to carry the missing offset values. With that, add the
SET_FIELD(), SET_REG() and GET_REG() macros that wrap the write_field(),
write_reg() and read_reg() functions to allow for making all demod
access code cleaner.

The write_field() function is annotated with __maybe_unused temporarily
to silence eventual compile warnings.

Picked up from the dddvb upstream, with the macro names made uppercase
so they are distinguishable as such.

Cc: Ralph Metzler 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0910.c | 28 
 1 file changed, 28 insertions(+)

diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index 06d2587125dd..5fed22685e28 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -194,6 +194,34 @@ static int write_shared_reg(struct stv *state, u16 reg, u8 
mask, u8 val)
return status;
 }
 
+static int __maybe_unused write_field(struct stv *state, u32 field, u8 val)
+{
+   int status;
+   u8 shift, mask, old, new;
+
+   status = read_reg(state, field >> 16, &old);
+   if (status)
+   return status;
+   mask = field & 0xff;
+   shift = (field >> 12) & 0xf;
+   new = ((val << shift) & mask) | (old & ~mask);
+   if (new == old)
+   return 0;
+   return write_reg(state, field >> 16, new);
+}
+
+#define SET_FIELD(_reg, _val)  \
+   write_field(state, state->nr ? FSTV0910_P2_##_reg : \
+   FSTV0910_P1_##_reg, _val)
+
+#define SET_REG(_reg, _val)\
+   write_reg(state, state->nr ? RSTV0910_P2_##_reg :   \
+ RSTV0910_P1_##_reg, _val)
+
+#define GET_REG(_reg, _val)\
+   read_reg(state, state->nr ? RSTV0910_P2_##_reg :\
+RSTV0910_P1_##_reg, _val)
+
 static const struct slookup s1_sn_lookup[] = {
{   0,9242  }, /* C/N=   0dB */
{   5,9105  }, /* C/N= 0.5dB */
-- 
2.13.6



[PATCH 4/4] [media] dvb-frontends/stv0910: cleanup init_search_param() and enable PLS

2017-12-26 Thread Daniel Scheller
From: Daniel Scheller 

Cleanup the mess in init_search_param() by utilising the new register
access macros and functions. And while at it, move the ISI and PLS setup
into separate functions, and pass the new scrambling_sequence_index (aka.
physical layer scrambling) value to set_pls.

Picked up from the dddvb upstream, adapted to the different naming of the
pls property (pls vs. scrambling_sequence_index).

Cc: Ralph Metzler 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0910.c | 113 --
 1 file changed, 52 insertions(+), 61 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index 5fed22685e28..b0c14ff74b67 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -194,7 +194,7 @@ static int write_shared_reg(struct stv *state, u16 reg, u8 
mask, u8 val)
return status;
 }
 
-static int __maybe_unused write_field(struct stv *state, u32 field, u8 val)
+static int write_field(struct stv *state, u32 field, u8 val)
 {
int status;
u8 shift, mask, old, new;
@@ -880,45 +880,60 @@ static int stop(struct stv *state)
return 0;
 }
 
-static int init_search_param(struct stv *state)
+static void set_pls(struct stv *state, u32 pls_code)
 {
-   u8 tmp;
-
-   read_reg(state, RSTV0910_P2_PDELCTRL1 + state->regoff, &tmp);
-   tmp |= 0x20; /* Filter_en (no effect if SIS=non-MIS */
-   write_reg(state, RSTV0910_P2_PDELCTRL1 + state->regoff, tmp);
-
-   read_reg(state, RSTV0910_P2_PDELCTRL2 + state->regoff, &tmp);
-   tmp &= ~0x02; /* frame mode = 0 */
-   write_reg(state, RSTV0910_P2_PDELCTRL2 + state->regoff, tmp);
-
-   write_reg(state, RSTV0910_P2_UPLCCST0 + state->regoff, 0xe0);
-   write_reg(state, RSTV0910_P2_ISIBITENA + state->regoff, 0x00);
-
-   read_reg(state, RSTV0910_P2_TSSTATEM + state->regoff, &tmp);
-   tmp &= ~0x01; /* nosync = 0, in case next signal is standard TS */
-   write_reg(state, RSTV0910_P2_TSSTATEM + state->regoff, tmp);
-
-   read_reg(state, RSTV0910_P2_TSCFGL + state->regoff, &tmp);
-   tmp &= ~0x04; /* embindvb = 0 */
-   write_reg(state, RSTV0910_P2_TSCFGL + state->regoff, tmp);
-
-   read_reg(state, RSTV0910_P2_TSINSDELH + state->regoff, &tmp);
-   tmp &= ~0x80; /* syncbyte = 0 */
-   write_reg(state, RSTV0910_P2_TSINSDELH + state->regoff, tmp);
-
-   read_reg(state, RSTV0910_P2_TSINSDELM + state->regoff, &tmp);
-   tmp &= ~0x08; /* token = 0 */
-   write_reg(state, RSTV0910_P2_TSINSDELM + state->regoff, tmp);
+   if (pls_code == state->cur_scrambling_code)
+   return;
+
+   /* PLROOT2 bit 2 = gold code */
+   write_reg(state, RSTV0910_P2_PLROOT0 + state->regoff,
+ pls_code & 0xff);
+   write_reg(state, RSTV0910_P2_PLROOT1 + state->regoff,
+ (pls_code >> 8) & 0xff);
+   write_reg(state, RSTV0910_P2_PLROOT2 + state->regoff,
+ 0x04 | ((pls_code >> 16) & 0x03));
+   state->cur_scrambling_code = pls_code;
+}
 
-   read_reg(state, RSTV0910_P2_TSDLYSET2 + state->regoff, &tmp);
-   tmp &= ~0x30; /* hysteresis threshold = 0 */
-   write_reg(state, RSTV0910_P2_TSDLYSET2 + state->regoff, tmp);
+static void set_isi(struct stv *state, u32 isi)
+{
+   if (isi == NO_STREAM_ID_FILTER)
+   return;
+   if (isi == 0x8000) {
+   SET_FIELD(FORCE_CONTINUOUS, 1);
+   SET_FIELD(TSOUT_NOSYNC, 1);
+   } else {
+   SET_FIELD(FILTER_EN, 1);
+   write_reg(state, RSTV0910_P2_ISIENTRY + state->regoff,
+ isi & 0xff);
+   write_reg(state, RSTV0910_P2_ISIBITENA + state->regoff, 0xff);
+   }
+   SET_FIELD(ALGOSWRST, 1);
+   SET_FIELD(ALGOSWRST, 0);
+}
 
-   read_reg(state, RSTV0910_P2_PDELCTRL0 + state->regoff, &tmp);
-   tmp = (tmp & ~0x30) | 0x10; /* isi obs mode = 1, observe min ISI */
-   write_reg(state, RSTV0910_P2_PDELCTRL0 + state->regoff, tmp);
+static void set_stream_modes(struct stv *state,
+struct dtv_frontend_properties *p)
+{
+   set_isi(state, p->stream_id);
+   set_pls(state, p->scrambling_sequence_index);
+}
 
+static int init_search_param(struct stv *state,
+struct dtv_frontend_properties *p)
+{
+   SET_FIELD(FORCE_CONTINUOUS, 0);
+   SET_FIELD(FRAME_MODE, 0);
+   SET_FIELD(FILTER_EN, 0);
+   SET_FIELD(TSOUT_NOSYNC, 0);
+   SET_FIELD(TSFIFO_EMBINDVB, 0);
+   SET_FIELD(TSDEL_SYNCBYTE, 0);
+   SET_REG(UPLCCST0, 0xe0);
+   SET_FIELD(TSINS_TOKEN, 0);
+   SET_FIELD(HYSTERESIS_THRESHOLD, 0);
+   SET_FIELD(ISIOBS_MODE, 1);
+
+   set_stream_modes(s

[PATCH 2/4] [media] dvb-frontends/stv0910: cleanup I2C access functions

2017-12-26 Thread Daniel Scheller
From: Daniel Scheller 

write_reg() and i2c_write_reg16() only act as a proxy to i2c_write(), which
isn't called from anywhere else throughout the driver. Clean this up by
moving the message setup and the i2c_transfer() into write_reg() so it
becomes the only I2C write function. While touching those parts, fix the
error codes from EREMOTEIO to EIO.

The I2C cleanup is picked from the upstream dddvb.

Cc: Ralph Metzler 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0910.c | 28 
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index a6c473f3647f..06d2587125dd 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -137,33 +137,21 @@ struct slookup {
u32  reg_value;
 };
 
-static inline int i2c_write(struct i2c_adapter *adap, u8 adr,
-   u8 *data, int len)
+static int write_reg(struct stv *state, u16 reg, u8 val)
 {
-   struct i2c_msg msg = {.addr = adr, .flags = 0,
- .buf = data, .len = len};
+   struct i2c_adapter *adap = state->base->i2c;
+   u8 data[3] = {reg >> 8, reg & 0xff, val};
+   struct i2c_msg msg = {.addr = state->base->adr, .flags = 0,
+ .buf = data, .len = 3};
 
if (i2c_transfer(adap, &msg, 1) != 1) {
dev_warn(&adap->dev, "i2c write error ([%02x] %04x: %02x)\n",
-adr, (data[0] << 8) | data[1],
-(len > 2 ? data[2] : 0));
-   return -EREMOTEIO;
+state->base->adr, reg, val);
+   return -EIO;
}
return 0;
 }
 
-static int i2c_write_reg16(struct i2c_adapter *adap, u8 adr, u16 reg, u8 val)
-{
-   u8 msg[3] = {reg >> 8, reg & 0xff, val};
-
-   return i2c_write(adap, adr, msg, 3);
-}
-
-static int write_reg(struct stv *state, u16 reg, u8 val)
-{
-   return i2c_write_reg16(state->base->i2c, state->base->adr, reg, val);
-}
-
 static inline int i2c_read_regs16(struct i2c_adapter *adapter, u8 adr,
  u16 reg, u8 *val, int count)
 {
@@ -176,7 +164,7 @@ static inline int i2c_read_regs16(struct i2c_adapter 
*adapter, u8 adr,
if (i2c_transfer(adapter, msgs, 2) != 2) {
dev_warn(&adapter->dev, "i2c read error ([%02x] %04x)\n",
 adr, reg);
-   return -EREMOTEIO;
+   return -EIO;
}
return 0;
 }
-- 
2.13.6



[PATCH 1/4] [media] dvb-frontends/stv0910: deduplicate writes in enable_puncture_rate()

2017-12-26 Thread Daniel Scheller
From: Daniel Scheller 

For all code rates, the same write is performed, only with a differing
value. Clean this up by putting that value into a variable instead and
perform the write at the end with that value.

Picked up from the dddvb upstream.

Cc: Ralph Metzler 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0910.c | 28 
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index a8c99f41478b..a6c473f3647f 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -908,27 +908,31 @@ static int init_search_param(struct stv *state)
 
 static int enable_puncture_rate(struct stv *state, enum fe_code_rate rate)
 {
+   u8 val;
+
switch (rate) {
case FEC_1_2:
-   return write_reg(state,
-RSTV0910_P2_PRVIT + state->regoff, 0x01);
+   val = 0x01;
+   break;
case FEC_2_3:
-   return write_reg(state,
-RSTV0910_P2_PRVIT + state->regoff, 0x02);
+   val = 0x02;
+   break;
case FEC_3_4:
-   return write_reg(state,
-RSTV0910_P2_PRVIT + state->regoff, 0x04);
+   val = 0x04;
+   break;
case FEC_5_6:
-   return write_reg(state,
-RSTV0910_P2_PRVIT + state->regoff, 0x08);
+   val = 0x08;
+   break;
case FEC_7_8:
-   return write_reg(state,
-RSTV0910_P2_PRVIT + state->regoff, 0x20);
+   val = 0x20;
+   break;
case FEC_NONE:
default:
-   return write_reg(state,
-RSTV0910_P2_PRVIT + state->regoff, 0x2f);
+   val = 0x2f;
+   break;
}
+
+   return write_reg(state, RSTV0910_P2_PRVIT + state->regoff, val);
 }
 
 static int set_vth_default(struct stv *state)
-- 
2.13.6



[PATCH 0/4] stv0910: upstream changes and PLS support

2017-12-26 Thread Daniel Scheller
From: Daniel Scheller 

This series basically is meant to fully enable support for physical
layer scrambling which is now supported by the DVB core. Though I
decided to pick up the latest changes to the driver from the dddvb
upstream and bring both drivers in sync. So, along with support for
PLS, these patches apply some cosmetics and cleanups, adds macros to
utilise the field definitions for which the offsets were added
recently, and makes use of them while finally enabling PLS.

Daniel Scheller (4):
  [media] dvb-frontends/stv0910: deduplicate writes in
enable_puncture_rate()
  [media] dvb-frontends/stv0910: cleanup I2C access functions
  [media] dvb-frontends/stv0910: field and register access helpers
  [media] dvb-frontends/stv0910: cleanup init_search_param() and enable
PLS

 drivers/media/dvb-frontends/stv0910.c | 195 ++
 1 file changed, 103 insertions(+), 92 deletions(-)

-- 
2.13.6



Re: [PATCH 0/2] Add FEC rates, S2X modulations and 64K transmission

2018-01-06 Thread Daniel Scheller
Am Thu, 21 Dec 2017 21:23:19 +0100
schrieb Daniel Scheller :

> From: Daniel Scheller 
> 
> As the DVB API is bumped to 5.11 for the next cycle.
> 
> dddvb brings a few additional FEC rates (1/4 and 1/3), 64/128/256APSK
> modulations (DVB-S2X) and the 64K transmission mode. These two rather
> trivial patches bring them to mainline, and puts these missing bits
> into the stv0910's get_frontend() callback (FEC 1/4 and 1/3 are
> handled throughout the rest of the demod driver already).
> 
> Let's have these enums as a part of DVB core 5.11.
> 
> Daniel Scheller (2):
>   media: dvb_frontend: add FEC modes, S2X modulations and 64K
> transmission
>   media: dvb-frontends/stv0910: report FEC 1/4 and 1/3 in
> get_frontend()
> 
>  Documentation/media/frontend.h.rst.exceptions |  6 ++
>  drivers/media/dvb-frontends/stv0910.c |  2 +-
>  include/uapi/linux/dvb/frontend.h | 13 +
>  3 files changed, 20 insertions(+), 1 deletion(-)

(Rather early) Ping - any chance these few constants/enums can make it
as part of DVB core 5.11?

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


[PATCH v2 2/5] media: dvb_frontend: add DVB-S2X rolloff factors

2018-01-22 Thread Daniel Scheller
From: Daniel Scheller 

Add 15%, 10% and 5% DVB-S2X rolloff factors. Also fix roloff typos.

Signed-off-by: Daniel Scheller 
---
 Documentation/media/frontend.h.rst.exceptions |  3 +++
 drivers/media/dvb-core/dvb_frontend.c |  9 +
 include/uapi/linux/dvb/frontend.h | 16 +++-
 3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/Documentation/media/frontend.h.rst.exceptions 
b/Documentation/media/frontend.h.rst.exceptions
index ae1148be0a39..c1643ce93426 100644
--- a/Documentation/media/frontend.h.rst.exceptions
+++ b/Documentation/media/frontend.h.rst.exceptions
@@ -167,6 +167,9 @@ ignore symbol ROLLOFF_35
 ignore symbol ROLLOFF_20
 ignore symbol ROLLOFF_25
 ignore symbol ROLLOFF_AUTO
+ignore symbol ROLLOFF_15
+ignore symbol ROLLOFF_10
+ignore symbol ROLLOFF_5
 
 ignore symbol INVERSION_ON
 ignore symbol INVERSION_OFF
diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index 722b86a43497..e5105c1783b8 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -2183,6 +2183,15 @@ static int dtv_set_frontend(struct dvb_frontend *fe)
break;
case SYS_DVBS2:
switch (c->rolloff) {
+   case ROLLOFF_5:
+   rolloff = 105;
+   break;
+   case ROLLOFF_10:
+   rolloff = 110;
+   break;
+   case ROLLOFF_15:
+   rolloff = 115;
+   break;
case ROLLOFF_20:
rolloff = 120;
break;
diff --git a/include/uapi/linux/dvb/frontend.h 
b/include/uapi/linux/dvb/frontend.h
index 227268a657cd..8bf1c63627a2 100644
--- a/include/uapi/linux/dvb/frontend.h
+++ b/include/uapi/linux/dvb/frontend.h
@@ -580,20 +580,26 @@ enum fe_pilot {
 
 /**
  * enum fe_rolloff - Rolloff factor
- * @ROLLOFF_35:Roloff factor: α=35%
- * @ROLLOFF_20:Roloff factor: α=20%
- * @ROLLOFF_25:Roloff factor: α=25%
- * @ROLLOFF_AUTO:  Auto-detect the roloff factor.
+ * @ROLLOFF_35:Rolloff factor: α=35%
+ * @ROLLOFF_20:Rolloff factor: α=20%
+ * @ROLLOFF_25:Rolloff factor: α=25%
+ * @ROLLOFF_AUTO:  Auto-detect the rolloff factor.
+ * @ROLLOFF_15:Rolloff factor: α=15%
+ * @ROLLOFF_10:Rolloff factor: α=10%
+ * @ROLLOFF_5: Rolloff factor: α=5%
  *
  * .. note:
  *
- *Roloff factor of 35% is implied on DVB-S. On DVB-S2, it is default.
+ *Rolloff factor of 35% is implied on DVB-S. On DVB-S2, it is default.
  */
 enum fe_rolloff {
ROLLOFF_35,
ROLLOFF_20,
ROLLOFF_25,
ROLLOFF_AUTO,
+   ROLLOFF_15,
+   ROLLOFF_10,
+   ROLLOFF_5,
 };
 
 /**
-- 
2.13.6



[PATCH v2 1/5] media: dvb_frontend: add FEC modes, S2X modulations and 64K transmission

2018-01-22 Thread Daniel Scheller
From: Daniel Scheller 

Add 1/4 and 1/3 FEC ratios, 64/128/256-APSK S2X modulations and 64K
transmission mode. Update relevant doc items aswell.

Signed-off-by: Daniel Scheller 
---
 Documentation/media/frontend.h.rst.exceptions |  6 ++
 include/uapi/linux/dvb/frontend.h | 13 +
 2 files changed, 19 insertions(+)

diff --git a/Documentation/media/frontend.h.rst.exceptions 
b/Documentation/media/frontend.h.rst.exceptions
index f7c4df620a52..ae1148be0a39 100644
--- a/Documentation/media/frontend.h.rst.exceptions
+++ b/Documentation/media/frontend.h.rst.exceptions
@@ -84,6 +84,9 @@ ignore symbol APSK_16
 ignore symbol APSK_32
 ignore symbol DQPSK
 ignore symbol QAM_4_NR
+ignore symbol APSK_64
+ignore symbol APSK_128
+ignore symbol APSK_256
 
 ignore symbol SEC_VOLTAGE_13
 ignore symbol SEC_VOLTAGE_18
@@ -117,6 +120,8 @@ ignore symbol FEC_AUTO
 ignore symbol FEC_3_5
 ignore symbol FEC_9_10
 ignore symbol FEC_2_5
+ignore symbol FEC_1_4
+ignore symbol FEC_1_3
 
 ignore symbol TRANSMISSION_MODE_AUTO
 ignore symbol TRANSMISSION_MODE_1K
@@ -129,6 +134,7 @@ ignore symbol TRANSMISSION_MODE_C1
 ignore symbol TRANSMISSION_MODE_C3780
 ignore symbol TRANSMISSION_MODE_2K
 ignore symbol TRANSMISSION_MODE_8K
+ignore symbol TRANSMISSION_MODE_64K
 
 ignore symbol GUARD_INTERVAL_AUTO
 ignore symbol GUARD_INTERVAL_1_128
diff --git a/include/uapi/linux/dvb/frontend.h 
b/include/uapi/linux/dvb/frontend.h
index 4f9b4551c534..227268a657cd 100644
--- a/include/uapi/linux/dvb/frontend.h
+++ b/include/uapi/linux/dvb/frontend.h
@@ -296,6 +296,8 @@ enum fe_spectral_inversion {
  * @FEC_3_5:  Forward Error Correction Code 3/5
  * @FEC_9_10: Forward Error Correction Code 9/10
  * @FEC_2_5:  Forward Error Correction Code 2/5
+ * @FEC_1_4:  Forward Error Correction Code 1/4
+ * @FEC_1_3:  Forward Error Correction Code 1/3
  *
  * Please note that not all FEC types are supported by a given standard.
  */
@@ -313,6 +315,8 @@ enum fe_code_rate {
FEC_3_5,
FEC_9_10,
FEC_2_5,
+   FEC_1_4,
+   FEC_1_3,
 };
 
 /**
@@ -331,6 +335,9 @@ enum fe_code_rate {
  * @APSK_32:   32-APSK modulation
  * @DQPSK: DQPSK modulation
  * @QAM_4_NR:  4-QAM-NR modulation
+ * @APSK_64:   64-APSK modulation
+ * @APSK_128:  128-APSK modulation
+ * @APSK_256:  256-APSK modulation
  *
  * Please note that not all modulations are supported by a given standard.
  *
@@ -350,6 +357,9 @@ enum fe_modulation {
APSK_32,
DQPSK,
QAM_4_NR,
+   APSK_64,
+   APSK_128,
+   APSK_256,
 };
 
 /**
@@ -374,6 +384,8 @@ enum fe_modulation {
  * Single Carrier (C=1) transmission mode (DTMB only)
  * @TRANSMISSION_MODE_C3780:
  * Multi Carrier (C=3780) transmission mode (DTMB only)
+ * @TRANSMISSION_MODE_64K:
+ * Transmission mode 64K
  *
  * Please note that not all transmission modes are supported by a given
  * standard.
@@ -388,6 +400,7 @@ enum fe_transmit_mode {
TRANSMISSION_MODE_32K,
TRANSMISSION_MODE_C1,
TRANSMISSION_MODE_C3780,
+   TRANSMISSION_MODE_64K,
 };
 
 /**
-- 
2.13.6



[PATCH v2 0/5] Add FEC rates, S2X params and 64K transmission

2018-01-22 Thread Daniel Scheller
From: Daniel Scheller 

dddvb brings a few additional FEC rates (1/4 and 1/3), 64/128/256APSK
modulations and more rolloff factors (DVB-S2X), and 64K transmission mode
(DVB-T2). These rather trivial patches bring them to mainline, and puts
these missing bits into the stv0910's get_frontend() callback (FEC 1/4
and 1/3 are handled throughout the rest of the demod driver already). In
addition (as suggestion from Richard Scobie), the stv0910 driver now
reports it's active delivery system.

Changes from v1 to v2:
- DVB-S2X rolloff factors and reporting
- report of the active delivery system in stv0910:get_frontend()

Daniel Scheller (5):
  media: dvb_frontend: add FEC modes, S2X modulations and 64K
transmission
  media: dvb_frontend: add DVB-S2X rolloff factors
  media: dvb-frontends/stv0910: report FEC 1/4 and 1/3 in get_frontend()
  media: dvb-frontends/stv0910: report S2 rolloff in get_frontend()
  media: dvb-frontends/stv0910: report active delsys in get_frontend()

 Documentation/media/frontend.h.rst.exceptions |  9 +
 drivers/media/dvb-core/dvb_frontend.c |  9 +
 drivers/media/dvb-frontends/stv0910.c | 16 ++-
 include/uapi/linux/dvb/frontend.h | 29 ++-
 4 files changed, 53 insertions(+), 10 deletions(-)

-- 
2.13.6



[PATCH v2 4/5] media: dvb-frontends/stv0910: report S2 rolloff in get_frontend()

2018-01-22 Thread Daniel Scheller
From: Daniel Scheller 

Report the currently used  S2 rolloff factor in get_frontend(). For
cosmetic reasons, also change all feroll_off occurences to fe_rolloff.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0910.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index de132a85e537..7ab014cec56c 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -113,7 +113,7 @@ struct stv {
enum fe_stv0910_mod_cod  mod_cod;
enum dvbs2_fectype   fectype;
u32  pilots;
-   enum fe_stv0910_roll_off feroll_off;
+   enum fe_stv0910_roll_off fe_rolloff;
 
int   is_standard_broadcast;
int   is_vcm;
@@ -541,7 +541,7 @@ static int get_signal_parameters(struct stv *state)
}
state->is_vcm = 0;
state->is_standard_broadcast = 1;
-   state->feroll_off = FE_SAT_35;
+   state->fe_rolloff = FE_SAT_35;
}
return 0;
 }
@@ -1300,14 +1300,14 @@ static int manage_matype_info(struct stv *state)
 
read_regs(state, RSTV0910_P2_MATSTR1 + state->regoff,
  bbheader, 2);
-   state->feroll_off =
+   state->fe_rolloff =
(enum fe_stv0910_roll_off)(bbheader[0] & 0x03);
state->is_vcm = (bbheader[0] & 0x10) == 0;
state->is_standard_broadcast = (bbheader[0] & 0xFC) == 0xF0;
} else if (state->receive_mode == RCVMODE_DVBS) {
state->is_vcm = 0;
state->is_standard_broadcast = 1;
-   state->feroll_off = FE_SAT_35;
+   state->fe_rolloff = FE_SAT_35;
}
return 0;
 }
@@ -1571,11 +1571,15 @@ static int get_frontend(struct dvb_frontend *fe,
FEC_3_4, FEC_4_5, FEC_5_6, FEC_8_9,
FEC_9_10
};
+   const enum fe_rolloff ro2ro[4] = {
+   ROLLOFF_35, ROLLOFF_25, ROLLOFF_20, ROLLOFF_15,
+   };
read_reg(state, RSTV0910_P2_DMDMODCOD + state->regoff, &tmp);
mc = ((tmp & 0x7c) >> 2);
p->pilot = (tmp & 0x01) ? PILOT_ON : PILOT_OFF;
p->modulation = modcod2mod[mc];
p->fec_inner = modcod2fec[mc];
+   p->rolloff = ro2ro[state->fe_rolloff];
} else if (state->receive_mode == RCVMODE_DVBS) {
read_reg(state, RSTV0910_P2_VITCURPUN + state->regoff, &tmp);
switch (tmp & 0x1F) {
-- 
2.13.6



[PATCH v2 5/5] media: dvb-frontends/stv0910: report active delsys in get_frontend()

2018-01-22 Thread Daniel Scheller
From: Daniel Scheller 

Report the active delivery system based on the receive_mode state of the
demodulator.

Suggested-by: Richard Scobie 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0910.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index 7ab014cec56c..6e6a70ad7354 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -1580,6 +1580,7 @@ static int get_frontend(struct dvb_frontend *fe,
p->modulation = modcod2mod[mc];
p->fec_inner = modcod2fec[mc];
p->rolloff = ro2ro[state->fe_rolloff];
+   p->delivery_system = SYS_DVBS2;
} else if (state->receive_mode == RCVMODE_DVBS) {
read_reg(state, RSTV0910_P2_VITCURPUN + state->regoff, &tmp);
switch (tmp & 0x1F) {
@@ -1603,6 +1604,7 @@ static int get_frontend(struct dvb_frontend *fe,
break;
}
p->rolloff = ROLLOFF_35;
+   p->delivery_system = SYS_DVBS;
}
 
if (state->receive_mode != RCVMODE_NONE) {
-- 
2.13.6



[PATCH v2 3/5] media: dvb-frontends/stv0910: report FEC 1/4 and 1/3 in get_frontend()

2018-01-22 Thread Daniel Scheller
From: Daniel Scheller 

The first two missing FECs in the modcod2fec fe_code_rate table were 1/4
and 1/3. Add them as they're now defined by the API.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0910.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index a2f7c0c1587f..de132a85e537 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -1562,7 +1562,7 @@ static int get_frontend(struct dvb_frontend *fe,
APSK_32,
};
const enum fe_code_rate modcod2fec[0x20] = {
-   FEC_NONE, FEC_NONE, FEC_NONE, FEC_2_5,
+   FEC_NONE, FEC_1_4, FEC_1_3, FEC_2_5,
FEC_1_2, FEC_3_5, FEC_2_3, FEC_3_4,
FEC_4_5, FEC_5_6, FEC_8_9, FEC_9_10,
FEC_3_5, FEC_2_3, FEC_3_4, FEC_5_6,
-- 
2.13.6



Re: [PATCH v3 1/3] [media] dvb_frontend: add S2X and misc. other enums

2018-05-07 Thread Daniel Scheller
Am Fri, 4 May 2018 12:51:02 -0300
schrieb Mauro Carvalho Chehab :

> Em Tue, 13 Mar 2018 23:18:03 +0100
> Daniel Scheller  escreveu:
> 
> > From: Daniel Scheller 
> > 
> > Additional enums:
> >  * FEC ratios 1/4 and 1/3
> >  * 64/128/256-APSK modulations (DVB-S2X)
> >  * 15%, 10% and 5% rolloff factors (DVB-S2X)
> >  * 64K transmission mode (DVB-T2)
> > 
> > Add these enums to the frontend.h docs exceptions aswell (uapi docs are
> > updated separately).
> > 
> > Also, bump the DVB API version to 5.12 to make userspace aware of these
> > new enums.  
> 
> Series look good, except for one detail: how userspace would know if
> a device supports S2(X) or not?

I don't think userspace (applications) actually do really need to
know since there's nothing additionally applications have to set up wrt
dealing with S2X. They simply set frequency, symbolrate and
optionally SYS_DVBS2 (and I have a feeling they don't even have to do
this since drivers or demods, even, will care about S or S2, or S2X
themselves). In fact, all that these patches do (and what is
necessary, and what S2X is about) is to add the enum values which demod
drivers then can report via the get_frontend IOCTL.

Of course we can add a SYS_DVBS2X and put that to the caps fe_ops of
S2X supporting drivers, but in the end we would only change all

  if (SYS_DVBS2...) {}

to

  if (SYS_DVBS2 || SYS_DVBS2X...) {}

as there are no new fancy properties for S2X but only more rolloffs and
modulation types. Adding a FE_CAN_DVBS2X won't work at this time since
there are no more bits left on this caps value.

So (since you marked the series as "Changes requested"), please maybe
reconsider, and I believe a SYS_DVBS2X would add more clutter than it'd
help. Or: Please advise.

Note: If you prefer to overhaul all the caps things (as we had a quick
chat about on IRC), I prefer to leave this task up to someone else due
to lack of time, and someone else even might even better know what's
necessary.

> 
> > 
> > Signed-off-by: Daniel Scheller 
> > ---
> > v2 to v3:
> > - All new enum patches squashed into one commit
> > - DVB API bump to 5.12
> > 
> > Please take note of some additional things in the cover letter.
> > 
> >  Documentation/media/frontend.h.rst.exceptions |  9 +
> >  drivers/media/dvb-core/dvb_frontend.c |  9 +
> >  include/uapi/linux/dvb/frontend.h | 29 
> > ++-
> >  include/uapi/linux/dvb/version.h  |  2 +-
> >  4 files changed, 43 insertions(+), 6 deletions(-)
> > 
> > diff --git a/Documentation/media/frontend.h.rst.exceptions 
> > b/Documentation/media/frontend.h.rst.exceptions
> > index f7c4df620a52..c1643ce93426 100644
> > --- a/Documentation/media/frontend.h.rst.exceptions
> > +++ b/Documentation/media/frontend.h.rst.exceptions
> > @@ -84,6 +84,9 @@ ignore symbol APSK_16
> >  ignore symbol APSK_32
> >  ignore symbol DQPSK
> >  ignore symbol QAM_4_NR
> > +ignore symbol APSK_64
> > +ignore symbol APSK_128
> > +ignore symbol APSK_256
> >  
> >  ignore symbol SEC_VOLTAGE_13
> >  ignore symbol SEC_VOLTAGE_18
> > @@ -117,6 +120,8 @@ ignore symbol FEC_AUTO
> >  ignore symbol FEC_3_5
> >  ignore symbol FEC_9_10
> >  ignore symbol FEC_2_5
> > +ignore symbol FEC_1_4
> > +ignore symbol FEC_1_3
> >  
> >  ignore symbol TRANSMISSION_MODE_AUTO
> >  ignore symbol TRANSMISSION_MODE_1K
> > @@ -129,6 +134,7 @@ ignore symbol TRANSMISSION_MODE_C1
> >  ignore symbol TRANSMISSION_MODE_C3780
> >  ignore symbol TRANSMISSION_MODE_2K
> >  ignore symbol TRANSMISSION_MODE_8K
> > +ignore symbol TRANSMISSION_MODE_64K
> >  
> >  ignore symbol GUARD_INTERVAL_AUTO
> >  ignore symbol GUARD_INTERVAL_1_128
> > @@ -161,6 +167,9 @@ ignore symbol ROLLOFF_35
> >  ignore symbol ROLLOFF_20
> >  ignore symbol ROLLOFF_25
> >  ignore symbol ROLLOFF_AUTO
> > +ignore symbol ROLLOFF_15
> > +ignore symbol ROLLOFF_10
> > +ignore symbol ROLLOFF_5
> >  
> >  ignore symbol INVERSION_ON
> >  ignore symbol INVERSION_OFF
> > diff --git a/drivers/media/dvb-core/dvb_frontend.c 
> > b/drivers/media/dvb-core/dvb_frontend.c
> > index a7ed16e0841d..52c76e32f864 100644
> > --- a/drivers/media/dvb-core/dvb_frontend.c
> > +++ b/drivers/media/dvb-core/dvb_frontend.c
> > @@ -2183,6 +2183,15 @@ static int dtv_set_frontend(struct dvb_frontend *fe)
> > break;
> > case SYS_DVBS2:
> > switch (c->rolloff) {
> > +   case ROLLOFF_5:
> > +   rolloff = 1

Re: [PATCH][media-next] media: ddbridge: avoid out-of-bounds write on array demod_in_use

2018-05-08 Thread Daniel Scheller
Hi Colin,

Am Tue,  8 May 2018 00:08:42 +0100
schrieb Colin King :

> From: Colin Ian King 
> 
> In function stop there is a check to see if state->demod is a stopped
> value of 0xff, however, later on, array demod_in_use is indexed with
> this value causing an out-of-bounds write error.  Avoid this by only
> writing to array demod_in_use if state->demod is not set to the stopped
> sentinal value for this specific corner case.  Also, replace the magic
> value 0xff with DEMOD_STOPPED to make code more readable.
> 
> Detected by CoverityScan, CID#1468550 ("Out-of-bounds write")
> 
> Fixes: daeeb1319e6f ("media: ddbridge: initial support for MCI-based MaxSX8 
> cards")
> Signed-off-by: Colin Ian King 
> ---
>  drivers/media/pci/ddbridge/ddbridge-mci.c | 11 +++
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.c 
> b/drivers/media/pci/ddbridge/ddbridge-mci.c
> index a85ff3e6b919..1f5ed53c8d35 100644
> --- a/drivers/media/pci/ddbridge/ddbridge-mci.c
> +++ b/drivers/media/pci/ddbridge/ddbridge-mci.c
> @@ -20,6 +20,8 @@
>  #include "ddbridge-io.h"
>  #include "ddbridge-mci.h"
>  
> +#define DEMOD_STOPPED(0xff)
> +
>  static LIST_HEAD(mci_list);
>  
>  static const u32 MCLK = (155000 / 12);
> @@ -193,7 +195,7 @@ static int stop(struct dvb_frontend *fe)
>   u32 input = state->tuner;
>  
>   memset(&cmd, 0, sizeof(cmd));
> - if (state->demod != 0xff) {
> + if (state->demod != DEMOD_STOPPED) {
>   cmd.command = MCI_CMD_STOP;
>   cmd.demod = state->demod;
>   mci_cmd(state, &cmd, NULL);
> @@ -209,10 +211,11 @@ static int stop(struct dvb_frontend *fe)
>   state->base->tuner_use_count[input]--;
>   if (!state->base->tuner_use_count[input])
>   mci_set_tuner(fe, input, 0);
> - state->base->demod_in_use[state->demod] = 0;
> + if (state->demod != DEMOD_STOPPED)
> + state->base->demod_in_use[state->demod] = 0;
>   state->base->used_ldpc_bitrate[state->nr] = 0;
> - state->demod = 0xff;
> - state->base->assigned_demod[state->nr] = 0xff;
> + state->demod = DEMOD_STOPPED;
> + state->base->assigned_demod[state->nr] = DEMOD_STOPPED;
>   state->base->iq_mode = 0;
>   mutex_unlock(&state->base->tuner_lock);
>   state->started = 0;

Thanks for the patch, or - better - pointing this out. While it's
unlikely this will ever be an issue, I'm fine with changing the code
like that, but I'd prefer to change it a bit differently (ie.
DEMOD_STOPPED should be DEMOD_UNUSED, and I'd add defines for max.
tuners and use/compare against them).

I'll send out a different patch that will cover the potential
coverityscan problem throughout the end of the week.

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


[PATCH 1/4] [media] ddbridge/mci: protect against out-of-bounds array access in stop()

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

In stop(), an (unlikely) out-of-bounds write error can occur when setting
the demod_in_use element indexed by state->demod to zero, as state->demod
isn't checked for being in the range of the array size of demod_in_use, and
state->demod maybe carrying the magic 0xff (demod unused) value. Prevent
this by checking state->demod not exceeding the array size before setting
the element value. To make the code a bit easier to read, replace the magic
value and the number of array elements with defines, and use them at a few
more places.

Detected by CoverityScan, CID#1468550 ("Out-of-bounds write")

Thanks to Colin for reporting the problem and providing an initial patch.

Fixes: daeeb1319e6f ("media: ddbridge: initial support for MCI-based MaxSX8 
cards")
Reported-by: Colin Ian King 
Cc: Ralph Metzler 
Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-mci.c | 21 +++--
 drivers/media/pci/ddbridge/ddbridge-mci.h |  4 
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.c 
b/drivers/media/pci/ddbridge/ddbridge-mci.c
index a85ff3e6b919..8d9592e75ad5 100644
--- a/drivers/media/pci/ddbridge/ddbridge-mci.c
+++ b/drivers/media/pci/ddbridge/ddbridge-mci.c
@@ -38,10 +38,10 @@ struct mci_base {
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];
+   u8   tuner_use_count[MCI_TUNER_MAX];
+   u8   assigned_demod[MCI_DEMOD_MAX];
+   u32  used_ldpc_bitrate[MCI_DEMOD_MAX];
+   u8   demod_in_use[MCI_DEMOD_MAX];
u32  iq_mode;
 };
 
@@ -193,7 +193,7 @@ static int stop(struct dvb_frontend *fe)
u32 input = state->tuner;
 
memset(&cmd, 0, sizeof(cmd));
-   if (state->demod != 0xff) {
+   if (state->demod != DEMOD_UNUSED) {
cmd.command = MCI_CMD_STOP;
cmd.demod = state->demod;
mci_cmd(state, &cmd, NULL);
@@ -209,10 +209,11 @@ static int stop(struct dvb_frontend *fe)
state->base->tuner_use_count[input]--;
if (!state->base->tuner_use_count[input])
mci_set_tuner(fe, input, 0);
-   state->base->demod_in_use[state->demod] = 0;
+   if (state->demod < MCI_DEMOD_MAX)
+   state->base->demod_in_use[state->demod] = 0;
state->base->used_ldpc_bitrate[state->nr] = 0;
-   state->demod = 0xff;
-   state->base->assigned_demod[state->nr] = 0xff;
+   state->demod = DEMOD_UNUSED;
+   state->base->assigned_demod[state->nr] = DEMOD_UNUSED;
state->base->iq_mode = 0;
mutex_unlock(&state->base->tuner_lock);
state->started = 0;
@@ -250,7 +251,7 @@ static int start(struct dvb_frontend *fe, u32 flags, u32 
modmask, u32 ts_config)
stat = -EBUSY;
goto unlock;
}
-   for (i = 0; i < 8; i++) {
+   for (i = 0; i < MCI_DEMOD_MAX; i++) {
used_ldpc_bitrate += state->base->used_ldpc_bitrate[i];
if (state->base->demod_in_use[i])
used_demods++;
@@ -342,7 +343,7 @@ static int start_iq(struct dvb_frontend *fe, u32 ts_config)
stat = -EBUSY;
goto unlock;
}
-   for (i = 0; i < 8; i++)
+   for (i = 0; i < MCI_DEMOD_MAX; i++)
if (state->base->demod_in_use[i])
used_demods++;
if (used_demods > 0) {
diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.h 
b/drivers/media/pci/ddbridge/ddbridge-mci.h
index c4193c5ee095..453dcb9f8208 100644
--- a/drivers/media/pci/ddbridge/ddbridge-mci.h
+++ b/drivers/media/pci/ddbridge/ddbridge-mci.h
@@ -19,6 +19,10 @@
 #ifndef _DDBRIDGE_MCI_H_
 #define _DDBRIDGE_MCI_H_
 
+#define MCI_DEMOD_MAX   8
+#define MCI_TUNER_MAX   4
+#define DEMOD_UNUSED(0xFF)
+
 #define MCI_CONTROL (0x500)
 #define MCI_COMMAND (0x600)
 #define MCI_RESULT  (0x680)
-- 
2.16.1



[PATCH 3/4] [media] dvb-frontends/stv0910: make TS speed configurable

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

Add a tsspeed config option to struct stv0910_cfg which can be used by
users of the driver to set the (parallel) TS speed (higher speeds enable
support for higher bitrate transponders). If tsspeed isn't set in the
config, it'll default to a sane value.

This commit also updates the two consumers of the stv0910 driver (ngene
and ddbridge) to have a default tsspeed in their stv0910_cfg templates.

Signed-off-by: Daniel Scheller 
Tested-by: Richard Scobie 
Tested-by: Helmut Auer 
---
 drivers/media/dvb-frontends/stv0910.c  | 5 ++---
 drivers/media/dvb-frontends/stv0910.h  | 1 +
 drivers/media/pci/ddbridge/ddbridge-core.c | 1 +
 drivers/media/pci/ngene/ngene-cards.c  | 1 +
 4 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index 7e9b016b3b28..41444fa1c0bb 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -1200,7 +1200,6 @@ static int probe(struct stv *state)
write_reg(state, RSTV0910_P1_TSCFGM, 0xC0); /* Manual speed */
write_reg(state, RSTV0910_P1_TSCFGL, 0x20);
 
-   /* Speed = 67.5 MHz */
write_reg(state, RSTV0910_P1_TSSPEED, state->tsspeed);
 
write_reg(state, RSTV0910_P2_TSCFGH, state->tscfgh | 0x01);
@@ -1208,7 +1207,6 @@ static int probe(struct stv *state)
write_reg(state, RSTV0910_P2_TSCFGM, 0xC0); /* Manual speed */
write_reg(state, RSTV0910_P2_TSCFGL, 0x20);
 
-   /* Speed = 67.5 MHz */
write_reg(state, RSTV0910_P2_TSSPEED, state->tsspeed);
 
/* Reset stream merger */
@@ -1790,7 +1788,8 @@ struct dvb_frontend *stv0910_attach(struct i2c_adapter 
*i2c,
state->tscfgh = 0x20 | (cfg->parallel ? 0 : 0x40);
state->tsgeneral = (cfg->parallel == 2) ? 0x02 : 0x00;
state->i2crpt = 0x0A | ((cfg->rptlvl & 0x07) << 4);
-   state->tsspeed = 0x28;
+   /* use safe tsspeed value if unspecified through stv0910_cfg */
+   state->tsspeed = (cfg->tsspeed ? cfg->tsspeed : 0x28);
state->nr = nr;
state->regoff = state->nr ? 0 : 0x200;
state->search_range = 1600;
diff --git a/drivers/media/dvb-frontends/stv0910.h 
b/drivers/media/dvb-frontends/stv0910.h
index fccd8d9b665f..f37171b7a2de 100644
--- a/drivers/media/dvb-frontends/stv0910.h
+++ b/drivers/media/dvb-frontends/stv0910.h
@@ -10,6 +10,7 @@ struct stv0910_cfg {
u8  parallel;
u8  rptlvl;
u8  single;
+   u8  tsspeed;
 };
 
 #if IS_REACHABLE(CONFIG_DVB_STV0910)
diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 377269c64449..6c2341642017 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1183,6 +1183,7 @@ static const struct stv0910_cfg stv0910_p = {
.parallel = 1,
.rptlvl   = 4,
.clk  = 3000,
+   .tsspeed  = 0x28,
 };
 
 static const struct lnbh25_config lnbh25_cfg = {
diff --git a/drivers/media/pci/ngene/ngene-cards.c 
b/drivers/media/pci/ngene/ngene-cards.c
index 7738565193d6..7a106bc11a2b 100644
--- a/drivers/media/pci/ngene/ngene-cards.c
+++ b/drivers/media/pci/ngene/ngene-cards.c
@@ -327,6 +327,7 @@ static struct stv0910_cfg stv0910_p = {
.parallel = 1,
.rptlvl   = 4,
.clk  = 3000,
+   .tsspeed  = 0x28,
 };
 
 static struct lnbh25_config lnbh25_cfg = {
-- 
2.16.1



[PATCH 2/4] [media] ddbridge/mci: add identifiers to function definition arguments

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

Fixes two checkpatch warnings

  WARNING: function definition argument 'xxx' should also have an identifier 
name

in the ddb_mci_attach() prototype definition. checkpatch keeps complaining
on the "int (**fn_set_input)" as it seems to have issues with the
ptr-to-ptr, though this probably needs fixing in checkpatch.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-mci.c | 2 +-
 drivers/media/pci/ddbridge/ddbridge-mci.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.c 
b/drivers/media/pci/ddbridge/ddbridge-mci.c
index 8d9592e75ad5..4ac634fc96e4 100644
--- a/drivers/media/pci/ddbridge/ddbridge-mci.c
+++ b/drivers/media/pci/ddbridge/ddbridge-mci.c
@@ -500,7 +500,7 @@ static int probe(struct mci *state)
 struct dvb_frontend
 *ddb_mci_attach(struct ddb_input *input,
int mci_type, int nr,
-   int (**fn_set_input)(struct dvb_frontend *, int))
+   int (**fn_set_input)(struct dvb_frontend *fe, int input))
 {
struct ddb_port *port = input->port;
struct ddb *dev = port->dev;
diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.h 
b/drivers/media/pci/ddbridge/ddbridge-mci.h
index 453dcb9f8208..209cc2b92dff 100644
--- a/drivers/media/pci/ddbridge/ddbridge-mci.h
+++ b/drivers/media/pci/ddbridge/ddbridge-mci.h
@@ -151,6 +151,6 @@ struct mci_result {
 struct dvb_frontend
 *ddb_mci_attach(struct ddb_input *input,
int mci_type, int nr,
-   int (**fn_set_input)(struct dvb_frontend *, int));
+   int (**fn_set_input)(struct dvb_frontend *fe, int input));
 
 #endif /* _DDBRIDGE_MCI_H_ */
-- 
2.16.1



[PATCH 0/4] ddbridge-0.9.33 fixes and improvements

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

Four post-ddbridge-0.9.33 patches fixing and improving a few things:

Patch 1 adds protection into the new ddbridge-mci code against an
out-of-bounds array write access as reported by CoverityScan and brought
to attention by Colin Ian King.

Patch 2 adds missing function argument identifiers to ddb_mci_attach() to
silence checkpatch. It still complains about the **fn_set_input which IS
the identifier but doesn't seem to be caught by checkpatch properly.

Patches 3 and 4 enable the higher speed TS mode on stv0910-equipped cards
and thus enables for higher bitrate transponders when the detected card
firmware permits this. This is basically what was removed in the initial
ddbridge-0.9.33 patch series but enhanced to be only enabled when the
FPGA firmware permits this.

Please merge, this should go in alongside the already merged ddbridge
0.9.33 patches. Thanks.

Daniel Scheller (4):
  [media] ddbridge/mci: protect against out-of-bounds array access in
stop()
  [media] ddbridge/mci: add identifiers to function definition arguments
  [media] dvb-frontends/stv0910: make TS speed configurable
  [media] ddbridge: conditionally enable fast TS for stv0910-equipped
bridges

 drivers/media/dvb-frontends/stv0910.c  |  5 ++---
 drivers/media/dvb-frontends/stv0910.h  |  1 +
 drivers/media/pci/ddbridge/ddbridge-core.c | 35 +-
 drivers/media/pci/ddbridge/ddbridge-mci.c  | 23 ++--
 drivers/media/pci/ddbridge/ddbridge-mci.h  |  6 -
 drivers/media/pci/ngene/ngene-cards.c  |  1 +
 6 files changed, 51 insertions(+), 20 deletions(-)

-- 
2.16.1



[PATCH 4/4] [media] ddbridge: conditionally enable fast TS for stv0910-equipped bridges

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

CineS2 V7(A) and Octopus CI S2 Pro/Advanced cards support faster TS speeds
on the card's contained stv0910 demodulator when their FPGA was updated
with a recent (>= 1.7, version number applies to all mentioned cards)
vendor firmware. Enable this faster TS speed on card port 0 (contained
demod) and parallel stv0910 connections when the card firmware is at least
1.7 or later.

Note: The mentioned cards and their demods are handled via the STV0910_PR
and STV0910_P tuner types. DuoFlex modules with such demodulators are
handled via the STV0910 (without suffix) types where such TS speed
increase doesn't technically make sense.

Signed-off-by: Daniel Scheller 
Tested-by: Richard Scobie 
Tested-by: Helmut Auer 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 34 +-
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 6c2341642017..d5b0d1eaf3ad 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1191,7 +1191,7 @@ static const struct lnbh25_config lnbh25_cfg = {
.data2_config = LNBH25_TEN
 };
 
-static int demod_attach_stv0910(struct ddb_input *input, int type)
+static int demod_attach_stv0910(struct ddb_input *input, int type, int tsfast)
 {
struct i2c_adapter *i2c = &input->port->i2c->adap;
struct ddb_dvb *dvb = &input->port->dvb[input->nr & 1];
@@ -1204,6 +1204,12 @@ static int demod_attach_stv0910(struct ddb_input *input, 
int type)
 
if (type)
cfg.parallel = 2;
+
+   if (tsfast) {
+   dev_info(dev, "Enabling stv0910 higher speed TS\n");
+   cfg.tsspeed = 0x10;
+   }
+
dvb->fe = dvb_attach(stv0910_attach, i2c, &cfg, (input->nr & 1));
if (!dvb->fe) {
cfg.adr = 0x6c;
@@ -1439,7 +1445,25 @@ static int dvb_input_attach(struct ddb_input *input)
struct ddb_port *port = input->port;
struct dvb_adapter *adap = dvb->adap;
struct dvb_demux *dvbdemux = &dvb->demux;
-   int par = 0, osc24 = 0;
+   struct ddb_ids *devids = &input->port->dev->link[input->port->lnr].ids;
+   int par = 0, osc24 = 0, tsfast = 0;
+
+   /*
+* Determine if bridges with stv0910 demods can run with fast TS and
+* thus support high bandwidth transponders.
+* STV0910_PR and STV0910_P tuner types covers all relevant bridges,
+* namely the CineS2 V7(A) and the Octopus CI S2 Pro/Advanced. All
+* DuoFlex S2 V4(A) have type=DDB_TUNER_DVBS_STV0910 without any suffix
+* and are limited by the serial link to the bridge, thus won't work
+* in fast TS mode.
+*/
+   if (port->nr == 0 &&
+   (port->type == DDB_TUNER_DVBS_STV0910_PR ||
+port->type == DDB_TUNER_DVBS_STV0910_P)) {
+   /* fast TS on port 0 requires FPGA version >= 1.7 */
+   if ((devids->hwid & 0x00ff) >= 0x00010007)
+   tsfast = 1;
+   }
 
dvb->attached = 0x01;
 
@@ -1496,19 +1520,19 @@ static int dvb_input_attach(struct ddb_input *input)
goto err_tuner;
break;
case DDB_TUNER_DVBS_STV0910:
-   if (demod_attach_stv0910(input, 0) < 0)
+   if (demod_attach_stv0910(input, 0, tsfast) < 0)
goto err_detach;
if (tuner_attach_stv6111(input, 0) < 0)
goto err_tuner;
break;
case DDB_TUNER_DVBS_STV0910_PR:
-   if (demod_attach_stv0910(input, 1) < 0)
+   if (demod_attach_stv0910(input, 1, tsfast) < 0)
goto err_detach;
if (tuner_attach_stv6111(input, 1) < 0)
goto err_tuner;
break;
case DDB_TUNER_DVBS_STV0910_P:
-   if (demod_attach_stv0910(input, 0) < 0)
+   if (demod_attach_stv0910(input, 0, tsfast) < 0)
goto err_detach;
if (tuner_attach_stv6111(input, 1) < 0)
goto err_tuner;
-- 
2.16.1



Re: [PATCH][media-next] media: ddbridge: avoid out-of-bounds write on array demod_in_use

2018-05-09 Thread Daniel Scheller
Hi Colin,

Am Tue, 8 May 2018 11:39:56 +0100
schrieb Colin Ian King :

> On 08/05/18 11:38, Daniel Scheller wrote:
> > Hi Colin,
> > 
> > Am Tue,  8 May 2018 00:08:42 +0100
> > schrieb Colin King :
> >   
> >> From: Colin Ian King 
> >>
> >> In function stop there is a check to see if state->demod is a stopped
> >> value of 0xff, however, later on, array demod_in_use is indexed with
> >> this value causing an out-of-bounds write error.  Avoid this by only
> >> writing to array demod_in_use if state->demod is not set to the stopped
> >> sentinal value for this specific corner case.  Also, replace the magic
> >> value 0xff with DEMOD_STOPPED to make code more readable.
> >>
> >> Detected by CoverityScan, CID#1468550 ("Out-of-bounds write")
> >>
> >> Fixes: daeeb1319e6f ("media: ddbridge: initial support for MCI-based 
> >> MaxSX8 cards")
> >> Signed-off-by: Colin Ian King 
> >> ---
> >>  drivers/media/pci/ddbridge/ddbridge-mci.c | 11 +++
> >>  1 file changed, 7 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.c 
> >> b/drivers/media/pci/ddbridge/ddbridge-mci.c
> >> index a85ff3e6b919..1f5ed53c8d35 100644
> >> --- a/drivers/media/pci/ddbridge/ddbridge-mci.c
> >> +++ b/drivers/media/pci/ddbridge/ddbridge-mci.c
> >> @@ -20,6 +20,8 @@
> >>  #include "ddbridge-io.h"
> >>  #include "ddbridge-mci.h"
> >>  
> >> +#define DEMOD_STOPPED (0xff)
> >> +
> >>  static LIST_HEAD(mci_list);
> >>  
> >>  static const u32 MCLK = (155000 / 12);
> >> @@ -193,7 +195,7 @@ static int stop(struct dvb_frontend *fe)
> >>u32 input = state->tuner;
> >>  
> >>memset(&cmd, 0, sizeof(cmd));
> >> -  if (state->demod != 0xff) {
> >> +  if (state->demod != DEMOD_STOPPED) {
> >>cmd.command = MCI_CMD_STOP;
> >>cmd.demod = state->demod;
> >>mci_cmd(state, &cmd, NULL);
> >> @@ -209,10 +211,11 @@ static int stop(struct dvb_frontend *fe)
> >>state->base->tuner_use_count[input]--;
> >>if (!state->base->tuner_use_count[input])
> >>mci_set_tuner(fe, input, 0);
> >> -  state->base->demod_in_use[state->demod] = 0;
> >> +  if (state->demod != DEMOD_STOPPED)
> >> +  state->base->demod_in_use[state->demod] = 0;
> >>state->base->used_ldpc_bitrate[state->nr] = 0;
> >> -  state->demod = 0xff;
> >> -  state->base->assigned_demod[state->nr] = 0xff;
> >> +  state->demod = DEMOD_STOPPED;
> >> +  state->base->assigned_demod[state->nr] = DEMOD_STOPPED;
> >>state->base->iq_mode = 0;
> >>mutex_unlock(&state->base->tuner_lock);
> >>state->started = 0;  
> > 
> > Thanks for the patch, or - better - pointing this out. While it's
> > unlikely this will ever be an issue, I'm fine with changing the code
> > like that, but I'd prefer to change it a bit differently (ie.
> > DEMOD_STOPPED should be DEMOD_UNUSED, and I'd add defines for max.
> > tuners and use/compare against them).  
> 
> Sounds like a good idea.
> 
> > 
> > I'll send out a different patch that will cover the potential
> > coverityscan problem throughout the end of the week.  
> 
> Great. Thanks!

JFYI, patch sent as part of a few other fixes and up at linux-media
patchwork:

https://patchwork.linuxtv.org/patch/49403/

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


[PATCH v3 0/3] IOCTLs in ddbridge

2018-05-12 Thread Daniel Scheller
From: Daniel Scheller 

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



[PATCH v3 2/3] [media] ddbridge: uAPI header for IOCTL definitions and related data structs

2018-05-12 Thread Daniel Scheller
From: Daniel Scheller 

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 
---
 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 
diff --git a/include/uapi/linux/ddbridge-ioctl.h 
b/include/uapi/linux/ddbridge-ioctl.h
new file mode 100644
index ..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 
+ * 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.
+ */
+
+#ifndef __LINUX_DDBRIDGE_IOCTL_H__
+#define __LINUX_DDBRIDGE_IOCTL_H__
+
+#include 
+#include 
+
+/**/
+
+#define DDB_IOCTL_MAGIC0xDD
+#define DDB_IOCTL_SEQIDX   0xE0
+
+/* DDB_IOCTL_FLASHIO */
+struct ddb_flashio {
+   /* write_*: userspace -> flash */
+   __user __u8 *write_buf;
+   __u32write_len;
+   /* read_*: flash -> userspace */
+   __user __u8 *read_buf;
+   __u32read_len;
+   /* card/addon link */
+   __u32link;
+};
+
+/* 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



[PATCH v3 3/3] [media] ddbridge: implement IOCTL handling

2018-05-12 Thread Daniel Scheller
From: Daniel Scheller 

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 
---
 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, 0x, 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, 0x, tag | SPI_DATA);
-   if (reg_

[PATCH v3 1/3] Documentation: ioctl-number: add ddbridge IOCTLs

2018-05-12 Thread Daniel Scheller
From: Daniel Scheller 

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-...@vger.kernel.org
Cc: linux-s...@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
Signed-off-by: Daniel Scheller 
---
 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 FileComments
 0xDB   00-0F   drivers/char/mwave/mwavepub.h
 0xDD   00-3F   ZFCP device driver  see drivers/s390/scsi/
<mailto:aherr...@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



[PATCH v3 5/9] [media] dvb-frontends/mxl5xx: add SPDX license identifier

2018-06-19 Thread Daniel Scheller
From: Daniel Scheller 

As it is clear that the driver is licensed under the terms of GPLv2-only
by now, add a matching SPDX license identifier to all driver files.

Cc: Ralph Metzler 
Cc: Manfred Voelkel 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/mxl5xx.c  | 1 +
 drivers/media/dvb-frontends/mxl5xx.h  | 1 +
 drivers/media/dvb-frontends/mxl5xx_defs.h | 1 +
 drivers/media/dvb-frontends/mxl5xx_regs.h | 1 +
 4 files changed, 4 insertions(+)

diff --git a/drivers/media/dvb-frontends/mxl5xx.c 
b/drivers/media/dvb-frontends/mxl5xx.c
index 323fd73d6e1e..922449f940a0 100644
--- a/drivers/media/dvb-frontends/mxl5xx.c
+++ b/drivers/media/dvb-frontends/mxl5xx.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Driver for the MaxLinear MxL5xx family of tuners/demods
  *
diff --git a/drivers/media/dvb-frontends/mxl5xx.h 
b/drivers/media/dvb-frontends/mxl5xx.h
index 2ee821b15693..5113759d7fb7 100644
--- a/drivers/media/dvb-frontends/mxl5xx.h
+++ b/drivers/media/dvb-frontends/mxl5xx.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * Driver for the MaxLinear MxL5xx family of tuners/demods
  *
diff --git a/drivers/media/dvb-frontends/mxl5xx_defs.h 
b/drivers/media/dvb-frontends/mxl5xx_defs.h
index fd5c0f5b27ba..295a2d75b5a7 100644
--- a/drivers/media/dvb-frontends/mxl5xx_defs.h
+++ b/drivers/media/dvb-frontends/mxl5xx_defs.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * Defines for the Maxlinear MX58x family of tuners/demods
  *
diff --git a/drivers/media/dvb-frontends/mxl5xx_regs.h 
b/drivers/media/dvb-frontends/mxl5xx_regs.h
index dacc1fdf4c7b..1b9715691b3c 100644
--- a/drivers/media/dvb-frontends/mxl5xx_regs.h
+++ b/drivers/media/dvb-frontends/mxl5xx_regs.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * Copyright (c) 2011-2013 MaxLinear, Inc. All rights reserved
  *
-- 
2.16.4



[PATCH v3 2/9] [media] ddbridge: add SPDX license identifiers

2018-06-19 Thread Daniel Scheller
From: Daniel Scheller 

Since the boilerplates and MODULE_LICENSE are now in sync regarding the
used license (GPL v2 only), add a matching GPLv2 SPDX license identifier
to all files of the ddbridge driver.

Cc: Ralph Metzler 
Cc: Manfred Voelkel 
Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-ci.c   | 1 +
 drivers/media/pci/ddbridge/ddbridge-ci.h   | 1 +
 drivers/media/pci/ddbridge/ddbridge-core.c | 1 +
 drivers/media/pci/ddbridge/ddbridge-hw.c   | 1 +
 drivers/media/pci/ddbridge/ddbridge-hw.h   | 1 +
 drivers/media/pci/ddbridge/ddbridge-i2c.c  | 1 +
 drivers/media/pci/ddbridge/ddbridge-i2c.h  | 1 +
 drivers/media/pci/ddbridge/ddbridge-io.h   | 1 +
 drivers/media/pci/ddbridge/ddbridge-main.c | 1 +
 drivers/media/pci/ddbridge/ddbridge-max.c  | 1 +
 drivers/media/pci/ddbridge/ddbridge-max.h  | 1 +
 drivers/media/pci/ddbridge/ddbridge-regs.h | 1 +
 drivers/media/pci/ddbridge/ddbridge.h  | 1 +
 13 files changed, 13 insertions(+)

diff --git a/drivers/media/pci/ddbridge/ddbridge-ci.c 
b/drivers/media/pci/ddbridge/ddbridge-ci.c
index cfe23d02e561..23b0e7d69e94 100644
--- a/drivers/media/pci/ddbridge/ddbridge-ci.c
+++ b/drivers/media/pci/ddbridge/ddbridge-ci.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * ddbridge-ci.c: Digital Devices bridge CI (DuoFlex, CI Bridge) support
  *
diff --git a/drivers/media/pci/ddbridge/ddbridge-ci.h 
b/drivers/media/pci/ddbridge/ddbridge-ci.h
index 35a39182dd83..c482132692f8 100644
--- a/drivers/media/pci/ddbridge/ddbridge-ci.h
+++ b/drivers/media/pci/ddbridge/ddbridge-ci.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * ddbridge-ci.h: Digital Devices bridge CI (DuoFlex, CI Bridge) support
  *
diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index d5b0d1eaf3ad..3a8bb652de56 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * ddbridge-core.c: Digital Devices bridge core functions
  *
diff --git a/drivers/media/pci/ddbridge/ddbridge-hw.c 
b/drivers/media/pci/ddbridge/ddbridge-hw.c
index 1d3ee6accdd5..39c2c1750b05 100644
--- a/drivers/media/pci/ddbridge/ddbridge-hw.c
+++ b/drivers/media/pci/ddbridge/ddbridge-hw.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * ddbridge-hw.c: Digital Devices bridge hardware maps
  *
diff --git a/drivers/media/pci/ddbridge/ddbridge-hw.h 
b/drivers/media/pci/ddbridge/ddbridge-hw.h
index 7c142419419c..72fd59e8c7c7 100644
--- a/drivers/media/pci/ddbridge/ddbridge-hw.h
+++ b/drivers/media/pci/ddbridge/ddbridge-hw.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * ddbridge-hw.h: Digital Devices bridge hardware maps
  *
diff --git a/drivers/media/pci/ddbridge/ddbridge-i2c.c 
b/drivers/media/pci/ddbridge/ddbridge-i2c.c
index 667340c86ea7..f7c4a88e3e66 100644
--- a/drivers/media/pci/ddbridge/ddbridge-i2c.c
+++ b/drivers/media/pci/ddbridge/ddbridge-i2c.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * ddbridge-i2c.c: Digital Devices bridge i2c driver
  *
diff --git a/drivers/media/pci/ddbridge/ddbridge-i2c.h 
b/drivers/media/pci/ddbridge/ddbridge-i2c.h
index 7ed220506c05..996462e51eab 100644
--- a/drivers/media/pci/ddbridge/ddbridge-i2c.h
+++ b/drivers/media/pci/ddbridge/ddbridge-i2c.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * ddbridge-i2c.c: Digital Devices bridge i2c driver
  *
diff --git a/drivers/media/pci/ddbridge/ddbridge-io.h 
b/drivers/media/pci/ddbridge/ddbridge-io.h
index b3646c04f1a7..c458df31cc43 100644
--- a/drivers/media/pci/ddbridge/ddbridge-io.h
+++ b/drivers/media/pci/ddbridge/ddbridge-io.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * ddbridge-io.h: Digital Devices bridge I/O inline functions
  *
diff --git a/drivers/media/pci/ddbridge/ddbridge-main.c 
b/drivers/media/pci/ddbridge/ddbridge-main.c
index 6f3ea927bde5..419a30bd9c21 100644
--- a/drivers/media/pci/ddbridge/ddbridge-main.c
+++ b/drivers/media/pci/ddbridge/ddbridge-main.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * ddbridge.c: Digital Devices PCIe bridge driver
  *
diff --git a/drivers/media/pci/ddbridge/ddbridge-max.c 
b/drivers/media/pci/ddbridge/ddbridge-max.c
index 739e4b444cf4..dc6276b0d10e 100644
--- a/drivers/media/pci/ddbridge/ddbridge-max.c
+++ b/drivers/media/pci/ddbridge/ddbridge-max.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * ddbridge-max.c: Digital Devices bridge MAX card support
  *
diff --git a/drivers/media/pci/ddbridge/ddbridge-max.h 
b/drivers/media/pci/ddbridge/ddbridge-max.h
index 82efc53baa94..cff35de3d173 100644
--- a/drivers/media/pci/ddbridge/ddbridge-max.h
+++ b/drivers/media/pci/ddbridge/ddbridge-max.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * ddbridge-max.h: Digital Devices bridge MAX card support
  *
diff --git a/drivers/media/pci/ddbridge/ddbridge-regs.h 
b/drivers/media/pci/ddbridge/ddbridge

[PATCH v3 1/9] [media] mxl5xx/stv0910/stv6111/ddbridge: fix MODULE_LICENSE to 'GPL v2'

2018-06-19 Thread Daniel Scheller
From: Daniel Scheller 

In commit 3db30defab4b ("use correct MODULE_LINCESE for GPL v2 only
according to notice in header") in the upstream repository for the
mentioned four drivers at https://github.com/DigitalDevices/dddvb.git
(plus a few more which aren't part of the mainline kernel tree), the
MODULE_LICENSE was fixed to "GPL v2" and are now in sync with the
GPL copyright boilerplate. Apply this change to the kernel tree
drivers aswell.

Cc: Ralph Metzler 
Cc: Manfred Voelkel 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/mxl5xx.c   | 2 +-
 drivers/media/dvb-frontends/stv0910.c  | 2 +-
 drivers/media/dvb-frontends/stv6111.c  | 2 +-
 drivers/media/pci/ddbridge/ddbridge-main.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/dvb-frontends/mxl5xx.c 
b/drivers/media/dvb-frontends/mxl5xx.c
index 274d8fca0763..1067701bdd06 100644
--- a/drivers/media/dvb-frontends/mxl5xx.c
+++ b/drivers/media/dvb-frontends/mxl5xx.c
@@ -1895,4 +1895,4 @@ EXPORT_SYMBOL_GPL(mxl5xx_attach);
 
 MODULE_DESCRIPTION("MaxLinear MxL5xx DVB-S/S2 tuner-demodulator driver");
 MODULE_AUTHOR("Ralph and Marcus Metzler, Metzler Brothers Systementwicklung 
GbR");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index 41444fa1c0bb..8d72de0ff5b0 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -1841,4 +1841,4 @@ EXPORT_SYMBOL_GPL(stv0910_attach);
 
 MODULE_DESCRIPTION("ST STV0910 multistandard frontend driver");
 MODULE_AUTHOR("Ralph and Marcus Metzler, Manfred Voelkel");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/dvb-frontends/stv6111.c 
b/drivers/media/dvb-frontends/stv6111.c
index 9b715b6fe152..25208a120cb7 100644
--- a/drivers/media/dvb-frontends/stv6111.c
+++ b/drivers/media/dvb-frontends/stv6111.c
@@ -688,4 +688,4 @@ EXPORT_SYMBOL_GPL(stv6111_attach);
 
 MODULE_DESCRIPTION("ST STV6111 satellite tuner driver");
 MODULE_AUTHOR("Ralph Metzler, Manfred Voelkel");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/pci/ddbridge/ddbridge-main.c 
b/drivers/media/pci/ddbridge/ddbridge-main.c
index f4748cfd904b..6f3ea927bde5 100644
--- a/drivers/media/pci/ddbridge/ddbridge-main.c
+++ b/drivers/media/pci/ddbridge/ddbridge-main.c
@@ -318,5 +318,5 @@ module_exit(module_exit_ddbridge);
 
 MODULE_DESCRIPTION("Digital Devices PCIe Bridge");
 MODULE_AUTHOR("Ralph and Marcus Metzler, Metzler Brothers Systementwicklung 
GbR");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
 MODULE_VERSION(DDBRIDGE_VERSION);
-- 
2.16.4



[PATCH v3 3/9] [media] ddbridge: header/boilerplate cleanups and cosmetics

2018-06-19 Thread Daniel Scheller
From: Daniel Scheller 

Cleanup whitespaces and blank lines, remove wrong links to
http://www.gnu.org/copyleft/gpl.html (the driver is licensed under the
terms of GPLv2, but the link points to a copy of the GPLv3), and fix
the filename reference in ddbridge-i2c.h.

Cc: Ralph Metzler 
Cc: Manfred Voelkel 
Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-ci.c   | 5 +
 drivers/media/pci/ddbridge/ddbridge-ci.h   | 5 +
 drivers/media/pci/ddbridge/ddbridge-core.c | 7 +--
 drivers/media/pci/ddbridge/ddbridge-hw.c   | 3 +--
 drivers/media/pci/ddbridge/ddbridge-hw.h   | 3 +--
 drivers/media/pci/ddbridge/ddbridge-i2c.c  | 3 +--
 drivers/media/pci/ddbridge/ddbridge-i2c.h  | 5 ++---
 drivers/media/pci/ddbridge/ddbridge-io.h   | 3 +--
 drivers/media/pci/ddbridge/ddbridge-main.c | 3 +--
 drivers/media/pci/ddbridge/ddbridge-max.c  | 3 +--
 drivers/media/pci/ddbridge/ddbridge-max.h  | 3 +--
 drivers/media/pci/ddbridge/ddbridge-regs.h | 6 +-
 drivers/media/pci/ddbridge/ddbridge.h  | 6 +-
 13 files changed, 14 insertions(+), 41 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-ci.c 
b/drivers/media/pci/ddbridge/ddbridge-ci.c
index 23b0e7d69e94..21cb7fc216ac 100644
--- a/drivers/media/pci/ddbridge/ddbridge-ci.c
+++ b/drivers/media/pci/ddbridge/ddbridge-ci.c
@@ -12,11 +12,8 @@
  *
  * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
- *
- * To obtain the license, point your browser to
- * http://www.gnu.org/copyleft/gpl.html
  */
 
 #include "ddbridge.h"
diff --git a/drivers/media/pci/ddbridge/ddbridge-ci.h 
b/drivers/media/pci/ddbridge/ddbridge-ci.h
index c482132692f8..f2fb2b670165 100644
--- a/drivers/media/pci/ddbridge/ddbridge-ci.h
+++ b/drivers/media/pci/ddbridge/ddbridge-ci.h
@@ -12,11 +12,8 @@
  *
  * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
- *
- * To obtain the license, point your browser to
- * http://www.gnu.org/copyleft/gpl.html
  */
 
 #ifndef __DDBRIDGE_CI_H__
diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 3a8bb652de56..c543e0ee7c76 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -6,19 +6,14 @@
  * Marcus Metzler 
  * Ralph 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
- *
- * To obtain the license, point your browser to
- * http://www.gnu.org/copyleft/gpl.html
  */
 
 #include 
diff --git a/drivers/media/pci/ddbridge/ddbridge-hw.c 
b/drivers/media/pci/ddbridge/ddbridge-hw.c
index 39c2c1750b05..c8160f523ea1 100644
--- a/drivers/media/pci/ddbridge/ddbridge-hw.c
+++ b/drivers/media/pci/ddbridge/ddbridge-hw.c
@@ -12,9 +12,8 @@
  *
  * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
- *
  */
 
 #include "ddbridge.h"
diff --git a/drivers/media/pci/ddbridge/ddbridge-hw.h 
b/drivers/media/pci/ddbridge/ddbridge-hw.h
index 72fd59e8c7c7..fe4ef7e080a4 100644
--- a/drivers/media/pci/ddbridge/ddbridge-hw.h
+++ b/drivers/media/pci/ddbridge/ddbridge-hw.h
@@ -12,9 +12,8 @@
  *
  * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
- *
  */
 
 #ifndef _DDBRIDGE_HW_H_
diff --git a/drivers/media/pci/ddbridge/ddbridge-i2c.c 
b/drivers/media/pci/ddbridge/ddbridge-i2c.c
index f7c4a88e3e66..822f9704190b 100644
--- a/drivers/media/pci/ddbridge/ddbridge-i2c.c
+++ b/drivers/media/pci/ddbridge/ddbridge-i2c.c
@@ -12,9 +12,8 @@
  *
  * This program is distributed in the hope th

[PATCH v3 9/9] [media] dvb-frontends/stv6111: add SPDX license identifier

2018-06-19 Thread Daniel Scheller
From: Daniel Scheller 

As it is clear that the driver is licensed under the terms of GPLv2-only
by now, add a matching SPDX license identifier to all driver files.

Cc: Ralph Metzler 
Cc: Manfred Voelkel 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv6111.c | 1 +
 drivers/media/dvb-frontends/stv6111.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/media/dvb-frontends/stv6111.c 
b/drivers/media/dvb-frontends/stv6111.c
index 88c0cf4c5011..4185441fa78b 100644
--- a/drivers/media/dvb-frontends/stv6111.c
+++ b/drivers/media/dvb-frontends/stv6111.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Driver for the ST STV6111 tuner
  *
diff --git a/drivers/media/dvb-frontends/stv6111.h 
b/drivers/media/dvb-frontends/stv6111.h
index 809e62361a91..8823eb326784 100644
--- a/drivers/media/dvb-frontends/stv6111.h
+++ b/drivers/media/dvb-frontends/stv6111.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * Driver for the ST STV6111 tuner
  *
-- 
2.16.4



[PATCH v3 7/9] [media] dvb-frontends/stv0910: add SPDX license identifier

2018-06-19 Thread Daniel Scheller
From: Daniel Scheller 

As it is clear that the driver is licensed under the terms of GPLv2-only
by now, add a matching SPDX license identifier to all driver files.

Cc: Ralph Metzler 
Cc: Manfred Voelkel 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0910.c  | 1 +
 drivers/media/dvb-frontends/stv0910.h  | 1 +
 drivers/media/dvb-frontends/stv0910_regs.h | 1 +
 3 files changed, 3 insertions(+)

diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index 16f73c16ac61..a81d3cc0acae 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Driver for the ST STV0910 DVB-S/S2 demodulator.
  *
diff --git a/drivers/media/dvb-frontends/stv0910.h 
b/drivers/media/dvb-frontends/stv0910.h
index c3985bee749f..19b48409e050 100644
--- a/drivers/media/dvb-frontends/stv0910.h
+++ b/drivers/media/dvb-frontends/stv0910.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * Driver for the ST STV0910 DVB-S/S2 demodulator.
  *
diff --git a/drivers/media/dvb-frontends/stv0910_regs.h 
b/drivers/media/dvb-frontends/stv0910_regs.h
index 4440892df61f..12ae86fae965 100644
--- a/drivers/media/dvb-frontends/stv0910_regs.h
+++ b/drivers/media/dvb-frontends/stv0910_regs.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * @DVB-S/DVB-S2 STMicroelectronics STV0900 register definitions
  * Author Manfred Voelkel, August 2013
-- 
2.16.4



[PATCH v3 8/9] [media] dvb-frontends/stv6111: cleanup and fix licensing boilerplates

2018-06-19 Thread Daniel Scheller
From: Daniel Scheller 

The stv6111.h doesn't carry any header nor any licensing boilerplate at
all, so copy this from the main driver file stv6111.c. While at it,
apply the usual whitespace/blank line cleanup.

Cc: Ralph Metzler 
Cc: Manfred Voelkel 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv6111.c |  3 +--
 drivers/media/dvb-frontends/stv6111.h | 15 +++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv6111.c 
b/drivers/media/dvb-frontends/stv6111.c
index 25208a120cb7..88c0cf4c5011 100644
--- a/drivers/media/dvb-frontends/stv6111.c
+++ b/drivers/media/dvb-frontends/stv6111.c
@@ -9,9 +9,8 @@
  *
  * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
- *
  */
 
 #include 
diff --git a/drivers/media/dvb-frontends/stv6111.h 
b/drivers/media/dvb-frontends/stv6111.h
index 5bc1228dc9bd..809e62361a91 100644
--- a/drivers/media/dvb-frontends/stv6111.h
+++ b/drivers/media/dvb-frontends/stv6111.h
@@ -1,3 +1,18 @@
+/*
+ * Driver for the ST STV6111 tuner
+ *
+ * Copyright (C) 2014 Digital Devices GmbH
+ *
+ * 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 _STV6111_H_
 #define _STV6111_H_
 
-- 
2.16.4



[PATCH v3 6/9] [media] dvb-frontends/stv0910: cleanup and fix licensing boilerplates

2018-06-19 Thread Daniel Scheller
From: Daniel Scheller 

The stv0910.h doesn't carry any header nor any licensing boilerplate at
all, so copy this from the main driver file stv0910.c. While at it,
apply the usual whitespace/blank line cleanup aswell.

Cc: Ralph Metzler 
Cc: Manfred Voelkel 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0910.c  |  2 +-
 drivers/media/dvb-frontends/stv0910.h  | 17 +
 drivers/media/dvb-frontends/stv0910_regs.h |  2 +-
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index 8d72de0ff5b0..16f73c16ac61 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -11,7 +11,7 @@
  *
  * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
  */
 
diff --git a/drivers/media/dvb-frontends/stv0910.h 
b/drivers/media/dvb-frontends/stv0910.h
index f37171b7a2de..c3985bee749f 100644
--- a/drivers/media/dvb-frontends/stv0910.h
+++ b/drivers/media/dvb-frontends/stv0910.h
@@ -1,3 +1,20 @@
+/*
+ * Driver for the ST STV0910 DVB-S/S2 demodulator.
+ *
+ * Copyright (C) 2014-2015 Ralph Metzler 
+ * Marcus Metzler 
+ * developed for Digital Devices GmbH
+ *
+ * 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 _STV0910_H_
 #define _STV0910_H_
 
diff --git a/drivers/media/dvb-frontends/stv0910_regs.h 
b/drivers/media/dvb-frontends/stv0910_regs.h
index f0eb915090bd..4440892df61f 100644
--- a/drivers/media/dvb-frontends/stv0910_regs.h
+++ b/drivers/media/dvb-frontends/stv0910_regs.h
@@ -1,7 +1,7 @@
 /*
  * @DVB-S/DVB-S2 STMicroelectronics STV0900 register definitions
  * Author Manfred Voelkel, August 2013
- * (c) 2013 Digital Devices GmbH Germany.  All rights reserved
+ * (c) 2013 Digital Devices GmbH Germany. All rights reserved
  *
  * ===
  * Registers Declaration (Internal ST, All Applications )
-- 
2.16.4



[PATCH v3 4/9] [media] dvb-frontends/mxl5xx: cleanup and fix licensing boilerplates

2018-06-19 Thread Daniel Scheller
From: Daniel Scheller 

mxl5xx.h doesn't carry any licensing boilerplate at all right now, so copy
the boilerplate over from the main driver file mxl5xx.c. Also, mxl5xx_defs
is missing a part of the licensing boilerplate text, so add it. While at
it, fix up some minor whitespace and blank line issues.

Cc: Ralph Metzler 
Cc: Manfred Voelkel 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/mxl5xx.c  |  3 +--
 drivers/media/dvb-frontends/mxl5xx.h  | 21 +
 drivers/media/dvb-frontends/mxl5xx_defs.h |  5 +
 drivers/media/dvb-frontends/mxl5xx_regs.h |  3 +--
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/drivers/media/dvb-frontends/mxl5xx.c 
b/drivers/media/dvb-frontends/mxl5xx.c
index 1067701bdd06..323fd73d6e1e 100644
--- a/drivers/media/dvb-frontends/mxl5xx.c
+++ b/drivers/media/dvb-frontends/mxl5xx.c
@@ -15,9 +15,8 @@
  *
  * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
- *
  */
 
 #include 
diff --git a/drivers/media/dvb-frontends/mxl5xx.h 
b/drivers/media/dvb-frontends/mxl5xx.h
index ad4c21846800..2ee821b15693 100644
--- a/drivers/media/dvb-frontends/mxl5xx.h
+++ b/drivers/media/dvb-frontends/mxl5xx.h
@@ -1,3 +1,24 @@
+/*
+ * Driver for the MaxLinear MxL5xx family of tuners/demods
+ *
+ * Copyright (C) 2014-2015 Ralph Metzler 
+ * Marcus Metzler 
+ * developed for Digital Devices GmbH
+ *
+ * based on code:
+ * Copyright (c) 2011-2013 MaxLinear, Inc. All rights reserved
+ * which was released under GPL V2
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2, 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 _MXL5XX_H_
 #define _MXL5XX_H_
 
diff --git a/drivers/media/dvb-frontends/mxl5xx_defs.h 
b/drivers/media/dvb-frontends/mxl5xx_defs.h
index fd9e61e0188f..fd5c0f5b27ba 100644
--- a/drivers/media/dvb-frontends/mxl5xx_defs.h
+++ b/drivers/media/dvb-frontends/mxl5xx_defs.h
@@ -10,6 +10,11 @@
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * version 2, 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.
  */
 
 enum MXL_BOOL_E {
diff --git a/drivers/media/dvb-frontends/mxl5xx_regs.h 
b/drivers/media/dvb-frontends/mxl5xx_regs.h
index 5001dafe1ba8..dacc1fdf4c7b 100644
--- a/drivers/media/dvb-frontends/mxl5xx_regs.h
+++ b/drivers/media/dvb-frontends/mxl5xx_regs.h
@@ -9,11 +9,10 @@
  *
  * 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.
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
details.
  *
  * This program may alternatively be licensed under a proprietary license from
  * MaxLinear, Inc.
- *
  */
 
 #ifndef __MXL58X_REGISTERS_H__
-- 
2.16.4



[PATCH v3 0/9] DD drivers: cleanup licensing

2018-06-19 Thread Daniel Scheller
From: Daniel Scheller 

Upstream committed a change to the dddvb driver package ([1]) that makes
things clear everything is licensed under the terms of the GPLv2-only.
So, apply the MODULE_LICENSE change to ddbridge, mxl5xx, stv0910 and
stv6111, and, as things are sorted now, apply SPDX license identifiers,
add missing header boilerplates in the DVB frontend drivers and fix up
a few cosmetics throughout the boilerplates.

One note re checkpatch and the order of the patches: I wanted to add
missing boilerplates where needed first before adding SPDX tags, so
checkpatch complains missing/malformed SPDX tags on those patches. Also,
I didn't want to touch the mxl5xx_regs more than needed, so checkpatch
moans about >80 columns in that patch/file.

Ralph/Manfred: Although all license related things should be clear by
now, please be so kind and send Acks (or complaints, if any) on these
patches so we can finally get rid of any mismatches in the in-kernel
drivers.

Changed in v3:
* (there was only one version posted so far but this is nonetheless
  the third iteration overall)
* Split up changes into more patches as requested by GregKH
* Note the change in the upstream driver package

[1] 
https://github.com/DigitalDevices/dddvb/commit/3db30defab4bd5429f6563b084a215b83da01ea0

Daniel Scheller (9):
  [media] mxl5xx/stv0910/stv6111/ddbridge: fix MODULE_LICENSE to 'GPL
v2'
  [media] ddbridge: add SPDX license identifiers
  [media] ddbridge: header/boilerplate cleanups and cosmetics
  [media] dvb-frontends/mxl5xx: cleanup and fix licensing boilerplates
  [media] dvb-frontends/mxl5xx: add SPDX license identifier
  [media] dvb-frontends/stv0910: cleanup and fix licensing boilerplates
  [media] dvb-frontends/stv0910: add SPDX license identifier
  [media] dvb-frontends/stv6111: cleanup and fix licensing boilerplates
  [media] dvb-frontends/stv6111: add SPDX license identifier

 drivers/media/dvb-frontends/mxl5xx.c   |  6 +++---
 drivers/media/dvb-frontends/mxl5xx.h   | 22 ++
 drivers/media/dvb-frontends/mxl5xx_defs.h  |  6 ++
 drivers/media/dvb-frontends/mxl5xx_regs.h  |  4 ++--
 drivers/media/dvb-frontends/stv0910.c  |  5 +++--
 drivers/media/dvb-frontends/stv0910.h  | 18 ++
 drivers/media/dvb-frontends/stv0910_regs.h |  3 ++-
 drivers/media/dvb-frontends/stv6111.c  |  6 +++---
 drivers/media/dvb-frontends/stv6111.h  | 16 
 drivers/media/pci/ddbridge/ddbridge-ci.c   |  6 ++
 drivers/media/pci/ddbridge/ddbridge-ci.h   |  6 ++
 drivers/media/pci/ddbridge/ddbridge-core.c |  8 ++--
 drivers/media/pci/ddbridge/ddbridge-hw.c   |  4 ++--
 drivers/media/pci/ddbridge/ddbridge-hw.h   |  4 ++--
 drivers/media/pci/ddbridge/ddbridge-i2c.c  |  4 ++--
 drivers/media/pci/ddbridge/ddbridge-i2c.h  |  6 +++---
 drivers/media/pci/ddbridge/ddbridge-io.h   |  4 ++--
 drivers/media/pci/ddbridge/ddbridge-main.c |  6 +++---
 drivers/media/pci/ddbridge/ddbridge-max.c  |  4 ++--
 drivers/media/pci/ddbridge/ddbridge-max.h  |  4 ++--
 drivers/media/pci/ddbridge/ddbridge-regs.h |  7 ++-
 drivers/media/pci/ddbridge/ddbridge.h  |  7 ++-
 22 files changed, 103 insertions(+), 53 deletions(-)

-- 
2.16.4



[PATCH 0/3] cxd2099: cleanup licensing

2018-06-19 Thread Daniel Scheller
From: Daniel Scheller 

Upstream committed a change to the dddvb driver package ([1]) that makes
things clear everything is licensed under the terms of the GPLv2-only.
So, apply the MODULE_LICENSE change to cxd2099 and, as things are sorted
now, apply SPDX license identifiers (and fix two spurious whitespaces).

Split from the series that touches all other Digital Devices drivers
since Jasmin is the maintainer for the cxd2099 driver.

Ralph/Manfred: Although all license related things should be clear by
now, please be so kind and send Acks (or complaints, if any) on these
patches so we can finally get rid of any mismatches in the in-kernel
drivers.

[1] 
https://github.com/DigitalDevices/dddvb/commit/3db30defab4bd5429f6563b084a215b83da01ea0

Daniel Scheller (3):
  [media] dvb-frontends/cxd2099: fix MODULE_LICENSE to 'GPL v2'
  [media] dvb-frontends/cxd2099: add SPDX license identifier
  [media] dvb-frontends/cxd2099: fix boilerplate whitespace

 drivers/media/dvb-frontends/cxd2099.c | 5 +++--
 drivers/media/dvb-frontends/cxd2099.h | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

-- 
2.16.4



[PATCH 1/3] [media] dvb-frontends/cxd2099: fix MODULE_LICENSE to 'GPL v2'

2018-06-19 Thread Daniel Scheller
From: Daniel Scheller 

In commit 3db30defab4b ("use correct MODULE_LINCESE for GPL v2 only
according to notice in header") in the upstream repository for the
mentioned driver at https://github.com/DigitalDevices/dddvb.git, the
MODULE_LICENSE was fixed to "GPL v2" and is now in sync with the GPL
copyright boilerplate. Apply this change to the kernel tree driver
aswell.

Cc: Ralph Metzler 
Cc: Manfred Voelkel 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/cxd2099.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/cxd2099.c 
b/drivers/media/dvb-frontends/cxd2099.c
index 4a0ce3037fd6..42de3d0badba 100644
--- a/drivers/media/dvb-frontends/cxd2099.c
+++ b/drivers/media/dvb-frontends/cxd2099.c
@@ -701,4 +701,4 @@ module_i2c_driver(cxd2099_driver);
 
 MODULE_DESCRIPTION("Sony CXD2099AR Common Interface controller driver");
 MODULE_AUTHOR("Ralph Metzler");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
-- 
2.16.4



[PATCH 3/3] [media] dvb-frontends/cxd2099: fix boilerplate whitespace

2018-06-19 Thread Daniel Scheller
From: Daniel Scheller 

There's a superfluous whitespace in the boilerplate license text in both
.c and .h files. Fix this.

Cc: Ralph Metzler 
Cc: Manfred Voelkel 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/cxd2099.c | 2 +-
 drivers/media/dvb-frontends/cxd2099.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/cxd2099.c 
b/drivers/media/dvb-frontends/cxd2099.c
index 5264e873850e..5d8884ed64ef 100644
--- a/drivers/media/dvb-frontends/cxd2099.c
+++ b/drivers/media/dvb-frontends/cxd2099.c
@@ -10,7 +10,7 @@
  *
  * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
  */
 
diff --git a/drivers/media/dvb-frontends/cxd2099.h 
b/drivers/media/dvb-frontends/cxd2099.h
index 0c101bdef01d..30787095843a 100644
--- a/drivers/media/dvb-frontends/cxd2099.h
+++ b/drivers/media/dvb-frontends/cxd2099.h
@@ -10,7 +10,7 @@
  *
  * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
  */
 
-- 
2.16.4



[PATCH 2/3] [media] dvb-frontends/cxd2099: add SPDX license identifier

2018-06-19 Thread Daniel Scheller
From: Daniel Scheller 

As both the MODULE_LICENSE and the boilerplates are now in sync and clear
that the driver is licensed under the terms of the GPLv2-only, add a
matching SPDX license identifier tag.

Cc: Ralph Metzler 
Cc: Manfred Voelkel 
Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/cxd2099.c | 1 +
 drivers/media/dvb-frontends/cxd2099.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/media/dvb-frontends/cxd2099.c 
b/drivers/media/dvb-frontends/cxd2099.c
index 42de3d0badba..5264e873850e 100644
--- a/drivers/media/dvb-frontends/cxd2099.c
+++ b/drivers/media/dvb-frontends/cxd2099.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * cxd2099.c: Driver for the Sony CXD2099AR Common Interface Controller
  *
diff --git a/drivers/media/dvb-frontends/cxd2099.h 
b/drivers/media/dvb-frontends/cxd2099.h
index ec1910dec3f3..0c101bdef01d 100644
--- a/drivers/media/dvb-frontends/cxd2099.h
+++ b/drivers/media/dvb-frontends/cxd2099.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 /*
  * cxd2099.h: Driver for the Sony CXD2099AR Common Interface Controller
  *
-- 
2.16.4



[PATCH 00/19] dddvb/ddbridge updates as of 2018-06-23

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

A bunch of commits as they appeared in the dddvb upstream GIT as of
2018-06-23, mainly cleanups, cosmetics and code move in preparation for
new MCI card types, plus improvements to the existing SX8 code, ie.
DVBv5 signal statistics.

Also fixes one sparse warning as being reported by Hans' daily media_tree
build in the mxl5xx driver.

Daniel Scheller (19):
  [media] dvb-frontends/mxl5xx: add break to case DVBS2 in
get_frontend()
  [media] dvb-frontends/stv0910: cast the BER denominator shift exp to
ULL
  [media] ddbridge: probe for LNBH25 chips before attaching
  [media] ddbridge: evaluate the actual link when setting up the dummy
tuner
  [media] ddbridge: report I2C bus errors
  [media] ddbridge: remove unused MDIO defines and hwinfo member
  [media] ddbridge: link structure access cosmetics in ddb_port_probe()
  [media] ddbridge: change MCI base ID and define a SX8 ID
  [media] ddbridge/mci: update copyright year in headers
  [media] ddbridge/mci: read and report signal strength and SNR
  [media] ddbridge/mci: rename defines and fix i/q var types
  [media] ddbridge/mci: extend mci_command and mci_result structs
  [media] ddbridge/mci: store mci type and number of ports in the hwinfo
  [media] ddbridge/mci: make ddb_mci_cmd() and ddb_mci_config() public
  [media] ddbridge/mci: split MaxSX8 specific code off to ddbridge-sx8.c
  [media] ddbridge/mci: add more MCI status codes, improve MCI_SUCCESS
macro
  [media] ddbridge/sx8: disable automatic PLS code search
  [media] ddbridge/sx8: enable modulation selection in set_parameters()
  [media] ddbridge/mci: add SX8 I/Q mode remark and remove DIAG CMD
defines

 drivers/media/dvb-frontends/mxl5xx.c   |   1 +
 drivers/media/dvb-frontends/stv0910.c  |   4 +-
 drivers/media/pci/ddbridge/Makefile|   3 +-
 drivers/media/pci/ddbridge/ddbridge-core.c |  45 +--
 drivers/media/pci/ddbridge/ddbridge-hw.c   |   3 +-
 drivers/media/pci/ddbridge/ddbridge-i2c.c  |   5 +-
 drivers/media/pci/ddbridge/ddbridge-max.c  |  18 +-
 drivers/media/pci/ddbridge/ddbridge-max.h  |   2 +-
 drivers/media/pci/ddbridge/ddbridge-mci.c  | 409 ++--
 drivers/media/pci/ddbridge/ddbridge-mci.h  | 192 ---
 drivers/media/pci/ddbridge/ddbridge-regs.h |   8 -
 drivers/media/pci/ddbridge/ddbridge-sx8.c  | 490 +
 drivers/media/pci/ddbridge/ddbridge.h  |  14 +-
 13 files changed, 718 insertions(+), 476 deletions(-)
 create mode 100644 drivers/media/pci/ddbridge/ddbridge-sx8.c

-- 
2.16.4



[PATCH 08/19] [media] ddbridge: change MCI base ID and define a SX8 ID

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

Change the start of the MCI ID range (internally used only) to 48 and
define an ID for the SX8 card type. Use this new ID to handle device
attachment.

This change is done in preparation for support of more MCI based cards.

Picked up from the upstream dddvb GIT.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 4 ++--
 drivers/media/pci/ddbridge/ddbridge.h  | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 408460be00b7..68ea0ffdad2d 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1592,7 +1592,7 @@ static int dvb_input_attach(struct ddb_input *input)
if (demod_attach_dummy(input) < 0)
goto err_detach;
break;
-   case DDB_TUNER_MCI:
+   case DDB_TUNER_MCI_SX8:
if (ddb_fe_attach_mci(input) < 0)
goto err_detach;
break;
@@ -1898,7 +1898,7 @@ static void ddb_port_probe(struct ddb_port *port)
port->name = "DUAL MCI";
port->type_name = "MCI";
port->class = DDB_PORT_TUNER;
-   port->type = DDB_TUNER_MCI;
+   port->type = DDB_TUNER_MCI_SX8;
return;
}
 
diff --git a/drivers/media/pci/ddbridge/ddbridge.h 
b/drivers/media/pci/ddbridge/ddbridge.h
index 9c645bee428a..65bd74d86ed5 100644
--- a/drivers/media/pci/ddbridge/ddbridge.h
+++ b/drivers/media/pci/ddbridge/ddbridge.h
@@ -254,7 +254,6 @@ struct ddb_port {
 #define DDB_CI_EXTERNAL_XO2_B13
 #define DDB_TUNER_DVBS_STV0910_PR 14
 #define DDB_TUNER_DVBC2T2I_SONY_P 15
-#define DDB_TUNER_MCI16
 
 #define DDB_TUNER_XO232
 #define DDB_TUNER_DVBS_STV0910   (DDB_TUNER_XO2 + 0)
@@ -264,6 +263,9 @@ struct ddb_port {
 #define DDB_TUNER_ATSC_ST(DDB_TUNER_XO2 + 4)
 #define DDB_TUNER_DVBC2T2I_SONY  (DDB_TUNER_XO2 + 5)
 
+#define DDB_TUNER_MCI48
+#define DDB_TUNER_MCI_SX8(DDB_TUNER_MCI + 0)
+
struct ddb_input  *input[2];
struct ddb_output *output;
struct dvb_ca_en50221 *en;
-- 
2.16.4



[PATCH 01/19] [media] dvb-frontends/mxl5xx: add break to case DVBS2 in get_frontend()

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

Fix one sparse warning:

drivers/media/dvb-frontends/mxl5xx.c:731:3: warning: this statement may 
fall through [-Wimplicit-fallthrough=]

as seen in Hans' daily media_tree builds.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/mxl5xx.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/dvb-frontends/mxl5xx.c 
b/drivers/media/dvb-frontends/mxl5xx.c
index 274d8fca0763..a7d08ace11ba 100644
--- a/drivers/media/dvb-frontends/mxl5xx.c
+++ b/drivers/media/dvb-frontends/mxl5xx.c
@@ -739,6 +739,7 @@ static int get_frontend(struct dvb_frontend *fe,
default:
break;
}
+   break;
case SYS_DVBS:
switch ((enum MXL_HYDRA_MODULATION_E)
reg_data[DMD_MODULATION_SCHEME_ADDR]) {
-- 
2.16.4



[PATCH 04/19] [media] ddbridge: evaluate the actual link when setting up the dummy tuner

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

Devices supporting dummy tuner operation can exist on any link, not only
on link 0, so fix this accordingly.

Picked up from the upstream dddvb GIT.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 3f83415b06c7..55eb151f329e 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1859,7 +1859,7 @@ static void ddb_port_probe(struct ddb_port *port)
/* Handle missing ports and ports without I2C */
 
if (dummy_tuner && !port->nr &&
-   dev->link[0].ids.device == 0x0005) {
+   dev->link[l].ids.device == 0x0005) {
port->name = "DUMMY";
port->class = DDB_PORT_TUNER;
port->type = DDB_TUNER_DUMMY;
-- 
2.16.4



[PATCH 05/19] [media] ddbridge: report I2C bus errors

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

The I2C_COMMAND response reports an error in the I2C bus communication
using bit 17. Evaluate the response more thoroughly and log an error
if an I2C problem was detected.

Picked up from the upstream dddvb GIT.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-i2c.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-i2c.c 
b/drivers/media/pci/ddbridge/ddbridge-i2c.c
index 667340c86ea7..5a28d7611713 100644
--- a/drivers/media/pci/ddbridge/ddbridge-i2c.c
+++ b/drivers/media/pci/ddbridge/ddbridge-i2c.c
@@ -73,7 +73,10 @@ static int ddb_i2c_cmd(struct ddb_i2c *i2c, u32 adr, u32 cmd)
}
return -EIO;
}
-   if (val & 0x7)
+   val &= 0x7;
+   if (val == 0x2)
+   dev_err(dev->dev, "I2C bus error\n");
+   if (val)
return -EIO;
return 0;
 }
-- 
2.16.4



[PATCH 18/19] [media] ddbridge/sx8: enable modulation selection in set_parameters()

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

Allow for tuning to transponders with specific modulations in
set_parameters(). Setting a specific modulation will also enable lower
modulations.

Picked up from the upstream dddvb GIT. Upstream also has support for
APSK64/128/256 modulations which aren't supported yet by the DVB
API, so comment them out until support for them is added.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-sx8.c | 30 +++---
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-sx8.c 
b/drivers/media/pci/ddbridge/ddbridge-sx8.c
index c87cefa10762..4418604258d1 100644
--- a/drivers/media/pci/ddbridge/ddbridge-sx8.c
+++ b/drivers/media/pci/ddbridge/ddbridge-sx8.c
@@ -372,15 +372,31 @@ static int set_parameters(struct dvb_frontend *fe)
if (iq_mode)
ts_config = (SX8_TSCONFIG_TSHEADER | SX8_TSCONFIG_MODE_IQ);
if (iq_mode < 3) {
-   u32 flags = 3;
-   u32 mask = 0x7f;
-
-   if (p->modulation == APSK_16 ||
-   p->modulation == APSK_32) {
-   flags = 2;
+   u32 mask;
+
+   switch (p->modulation) {
+   /* uncomment whenever these modulations hit the DVB API
+*  case APSK_256:
+*  mask = 0x7f;
+*  break;
+*  case APSK_128:
+*  mask = 0x3f;
+*  break;
+*  case APSK_64:
+*  mask = 0x1f;
+*  break;
+*/
+   case APSK_32:
mask = 0x0f;
+   break;
+   case APSK_16:
+   mask = 0x07;
+   break;
+   default:
+   mask = 0x03;
+   break;
}
-   stat = start(fe, flags, mask, ts_config);
+   stat = start(fe, 3, mask, ts_config);
} else {
u32 flags = (iq_mode == 2) ? 1 : 0;
 
-- 
2.16.4



[PATCH 12/19] [media] ddbridge/mci: extend mci_command and mci_result structs

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

Recent FPGA firmware reports more data and values in sent command
responses. Adjust the mci_command and mci_result structs including it's
unions to match these changes and add a few comments explaining things.

Picked up from the upstream dddvb GIT.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-mci.h | 74 +++
 1 file changed, 66 insertions(+), 8 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.h 
b/drivers/media/pci/ddbridge/ddbridge-mci.h
index 2e74f0544717..5e0c9e88b6fc 100644
--- a/drivers/media/pci/ddbridge/ddbridge-mci.h
+++ b/drivers/media/pci/ddbridge/ddbridge-mci.h
@@ -90,16 +90,30 @@ struct mci_command {
union {
u32 command_word;
struct {
-   u8 command;
-   u8 tuner;
-   u8 demod;
-   u8 output;
+   u8  command;
+   u8  tuner;
+   u8  demod;
+   u8  output;
};
};
union {
u32 params[31];
struct {
+   /*
+* Bit 0: DVB-S Enabled
+* Bit 1: DVB-S2 Enabled
+* Bit 7: InputStreamID
+*/
u8  flags;
+   /*
+* Bit 0: QPSK,
+* Bit 1: 8PSK/8APSK
+* Bit 2: 16APSK
+* Bit 3: 32APSK
+* Bit 4: 64APSK
+* Bit 5: 128APSK
+* Bit 6: 256APSK
+*/
u8  s2_modulation_mask;
u8  rsvd1;
u8  retry;
@@ -108,7 +122,36 @@ struct mci_command {
u8  input_stream_id;
u8  rsvd2[3];
u32 scrambling_sequence_index;
+   u32 frequency_range;
} dvbs2_search;
+
+   struct {
+   u8  tap;
+   u8  rsvd;
+   u16 point;
+   } get_iq_symbol;
+
+   struct {
+   /*
+* Bit 0: 0=VTM/1=SCAN
+* Bit 1: Set Gain
+*/
+   u8  flags;
+   u8  roll_off;
+   u8  rsvd1;
+   u8  rsvd2;
+   u32 frequency;
+   u32 symbol_rate; /* Only in VTM mode */
+   u16 gain;
+   } sx8_start_iq;
+
+   struct {
+   /*
+* Bit 1:0 = STVVGLNA Gain.
+*   0 = AGC, 1 = 0dB, 2 = Minimum, 3 = Maximum
+*/
+   u8  flags;
+   } sx8_input_enable;
};
 };
 
@@ -116,34 +159,49 @@ struct mci_result {
union {
u32 status_word;
struct {
-   u8 status;
-   u8 rsvd;
+   u8  status;
+   u8  mode;
u16 time;
};
};
union {
u32 result[27];
struct {
+   /* 1 = DVB-S, 2 = DVB-S2X */
u8  standard;
/* puncture rate for DVB-S */
u8  pls_code;
-   /* 7-6: rolloff, 5-2: rsrvd, 1:short, 0:pilots */
+   /* 2-0: rolloff */
u8  roll_off;
u8  rsvd;
+   /* actual frequency in Hz */
u32 frequency;
+   /* actual symbolrate in Hz */
u32 symbol_rate;
+   /* channel power in dBm x 100 */
s16 channel_power;
+   /* band power in dBm x 100 */
s16 band_power;
+   /*
+* SNR in dB x 100
+* Note: negative values are valid in DVB-S2
+*/
s16 signal_to_noise;
s16 rsvd2;
+   /*
+* Counter for packet errors
+* (set to 0 on start command)
+*/
u32 packet_errors;
+   /* Bit error rate: PreRS in DVB-S, PreBCH in DVB-S2X */
u32 ber_numerator;
u32 ber_denominator;
} dvbs2_signal_info;
+
struct {
s16 i;

[PATCH 09/19] [media] ddbridge/mci: update copyright year in headers

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

Update the copyright year information in the MCI headers to 2017-2018.

Picked up from the upstream dddvb GIT.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-mci.c | 6 +++---
 drivers/media/pci/ddbridge/ddbridge-mci.h | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.c 
b/drivers/media/pci/ddbridge/ddbridge-mci.c
index 4ac634fc96e4..46b20b06e2a6 100644
--- a/drivers/media/pci/ddbridge/ddbridge-mci.c
+++ b/drivers/media/pci/ddbridge/ddbridge-mci.c
@@ -2,9 +2,9 @@
 /*
  * ddbridge-mci.c: Digital Devices microcode interface
  *
- * Copyright (C) 2017 Digital Devices GmbH
- *Ralph Metzler 
- *Marcus Metzler 
+ * Copyright (C) 2017-2018 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
diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.h 
b/drivers/media/pci/ddbridge/ddbridge-mci.h
index 209cc2b92dff..389f6376603b 100644
--- a/drivers/media/pci/ddbridge/ddbridge-mci.h
+++ b/drivers/media/pci/ddbridge/ddbridge-mci.h
@@ -2,9 +2,9 @@
 /*
  * ddbridge-mci.h: Digital Devices micro code interface
  *
- * Copyright (C) 2017 Digital Devices GmbH
- *Marcus Metzler 
- *Ralph Metzler 
+ * Copyright (C) 2017-2018 Digital Devices GmbH
+ * Marcus Metzler 
+ * Ralph Metzler 
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
-- 
2.16.4



[PATCH 10/19] [media] ddbridge/mci: read and report signal strength and SNR

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

Implement querying signal statistics from the MCI and report this data
in read_status() as DVBv5 statistics.

Picked up from the upstream dddvb GIT.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-mci.c | 47 ++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.c 
b/drivers/media/pci/ddbridge/ddbridge-mci.c
index 46b20b06e2a6..7d402861fa9e 100644
--- a/drivers/media/pci/ddbridge/ddbridge-mci.c
+++ b/drivers/media/pci/ddbridge/ddbridge-mci.c
@@ -155,6 +155,47 @@ static void release(struct dvb_frontend *fe)
kfree(state);
 }
 
+static int get_info(struct dvb_frontend *fe)
+{
+   int stat;
+   struct mci *state = fe->demodulator_priv;
+   struct mci_command cmd;
+
+   memset(&cmd, 0, sizeof(cmd));
+   cmd.command = MCI_CMD_GETSIGNALINFO;
+   cmd.demod = state->demod;
+   stat = mci_cmd(state, &cmd, &state->signal_info);
+   return stat;
+}
+
+static int get_snr(struct dvb_frontend *fe)
+{
+   struct mci *state = fe->demodulator_priv;
+   struct dtv_frontend_properties *p = &fe->dtv_property_cache;
+
+   p->cnr.len = 1;
+   p->cnr.stat[0].scale = FE_SCALE_DECIBEL;
+   p->cnr.stat[0].svalue =
+   (s64)state->signal_info.dvbs2_signal_info.signal_to_noise
+* 10;
+   return 0;
+}
+
+static int get_strength(struct dvb_frontend *fe)
+{
+   struct mci *state = fe->demodulator_priv;
+   struct dtv_frontend_properties *p = &fe->dtv_property_cache;
+   s32 str;
+
+   str = 10 -
+ (state->signal_info.dvbs2_signal_info.channel_power
+  * 10 + 108750);
+   p->strength.len = 1;
+   p->strength.stat[0].scale = FE_SCALE_DECIBEL;
+   p->strength.stat[0].svalue = str;
+   return 0;
+}
+
 static int read_status(struct dvb_frontend *fe, enum fe_status *status)
 {
int stat;
@@ -168,10 +209,14 @@ static int read_status(struct dvb_frontend *fe, enum 
fe_status *status)
if (stat)
return stat;
*status = 0x00;
+   get_info(fe);
+   get_strength(fe);
if (res.status == SX8_DEMOD_WAIT_MATYPE)
*status = 0x0f;
-   if (res.status == SX8_DEMOD_LOCKED)
+   if (res.status == SX8_DEMOD_LOCKED) {
*status = 0x1f;
+   get_snr(fe);
+   }
return stat;
 }
 
-- 
2.16.4



[PATCH 13/19] [media] ddbridge/mci: store mci type and number of ports in the hwinfo

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

For better support for future MCI based cards, rename the mci struct
member to mci_ports to carry the number of ports on the cards, and add a
mci_type member to identify the card type to handle differing hardware.

Picked up from the upstream dddvb GIT.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 4 ++--
 drivers/media/pci/ddbridge/ddbridge-hw.c   | 3 ++-
 drivers/media/pci/ddbridge/ddbridge.h  | 9 ++---
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 68ea0ffdad2d..67b60da12cf4 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1893,12 +1893,12 @@ static void ddb_port_probe(struct ddb_port *port)
}
 
if (link->info->type == DDB_OCTOPUS_MCI) {
-   if (port->nr >= link->info->mci)
+   if (port->nr >= link->info->mci_ports)
return;
port->name = "DUAL MCI";
port->type_name = "MCI";
port->class = DDB_PORT_TUNER;
-   port->type = DDB_TUNER_MCI_SX8;
+   port->type = DDB_TUNER_MCI + link->info->mci_type;
return;
}
 
diff --git a/drivers/media/pci/ddbridge/ddbridge-hw.c 
b/drivers/media/pci/ddbridge/ddbridge-hw.c
index 1d3ee6accdd5..f3cbac07b41f 100644
--- a/drivers/media/pci/ddbridge/ddbridge-hw.c
+++ b/drivers/media/pci/ddbridge/ddbridge-hw.c
@@ -318,7 +318,8 @@ static const struct ddb_info ddb_s2x_48 = {
.port_num = 4,
.i2c_mask = 0x00,
.tempmon_irq = 24,
-   .mci  = 4
+   .mci_ports = 4,
+   .mci_type = 0,
 };
 
 //
diff --git a/drivers/media/pci/ddbridge/ddbridge.h 
b/drivers/media/pci/ddbridge/ddbridge.h
index 65bd74d86ed5..8a354dfb6c22 100644
--- a/drivers/media/pci/ddbridge/ddbridge.h
+++ b/drivers/media/pci/ddbridge/ddbridge.h
@@ -120,20 +120,23 @@ struct ddb_info {
 #define DDB_OCTOPUS_MCI 9
char *name;
u32   i2c_mask;
+   u32   board_control;
+   u32   board_control_2;
+
u8port_num;
u8led_num;
u8fan_num;
u8temp_num;
u8temp_bus;
-   u32   board_control;
-   u32   board_control_2;
u8con_clock; /* use a continuous clock */
u8ts_quirks;
 #define TS_QUIRK_SERIAL   1
 #define TS_QUIRK_REVERSED 2
 #define TS_QUIRK_ALT_OSC  8
+   u8mci_ports;
+   u8mci_type;
+
u32   tempmon_irq;
-   u8mci;
const struct ddb_regmap *regmap;
 };
 
-- 
2.16.4



[PATCH 02/19] [media] dvb-frontends/stv0910: cast the BER denominator shift exp to ULL

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

To avoid miscalculations related to the BER denominator, the shift
expression needs to be casted as ULL.

Picked up from the upstream dddvb GIT.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0910.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index 41444fa1c0bb..91b21eb59531 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -682,8 +682,8 @@ static int get_bit_error_rate_s(struct stv *state, u32 
*bernumerator,
return -EINVAL;
 
if ((regs[0] & 0x80) == 0) {
-   state->last_berdenominator = 1 << ((state->berscale * 2) +
- 10 + 3);
+   state->last_berdenominator = 1ULL << ((state->berscale * 2) +
+10 + 3);
state->last_bernumerator = ((u32)(regs[0] & 0x7F) << 16) |
((u32)regs[1] << 8) | regs[2];
if (state->last_bernumerator < 256 && state->berscale < 6) {
-- 
2.16.4



[PATCH 07/19] [media] ddbridge: link structure access cosmetics in ddb_port_probe()

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

Throughout the function, dev->link[l] is used several times. Unclutter
this a bit by declaring a ddb_link var at the top of the function, assign
the address of dev->link[l] to it and use that var to access the link[]
struct member.

Picked up from the upstream dddvb GIT.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 55eb151f329e..408460be00b7 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1850,6 +1850,7 @@ static void ddb_port_probe(struct ddb_port *port)
 {
struct ddb *dev = port->dev;
u32 l = port->lnr;
+   struct ddb_link *link = &dev->link[l];
u8 id, type;
 
port->name = "NO MODULE";
@@ -1859,7 +1860,7 @@ static void ddb_port_probe(struct ddb_port *port)
/* Handle missing ports and ports without I2C */
 
if (dummy_tuner && !port->nr &&
-   dev->link[l].ids.device == 0x0005) {
+   link->ids.device == 0x0005) {
port->name = "DUMMY";
port->class = DDB_PORT_TUNER;
port->type = DDB_TUNER_DUMMY;
@@ -1873,14 +1874,14 @@ static void ddb_port_probe(struct ddb_port *port)
return;
}
 
-   if (port->nr == 1 && dev->link[l].info->type == DDB_OCTOPUS_CI &&
-   dev->link[l].info->i2c_mask == 1) {
+   if (port->nr == 1 && link->info->type == DDB_OCTOPUS_CI &&
+   link->info->i2c_mask == 1) {
port->name = "NO TAB";
port->class = DDB_PORT_NONE;
return;
}
 
-   if (dev->link[l].info->type == DDB_OCTOPUS_MAX) {
+   if (link->info->type == DDB_OCTOPUS_MAX) {
port->name = "DUAL DVB-S2 MAX";
port->type_name = "MXL5XX";
port->class = DDB_PORT_TUNER;
@@ -1891,8 +1892,8 @@ static void ddb_port_probe(struct ddb_port *port)
return;
}
 
-   if (dev->link[l].info->type == DDB_OCTOPUS_MCI) {
-   if (port->nr >= dev->link[l].info->mci)
+   if (link->info->type == DDB_OCTOPUS_MCI) {
+   if (port->nr >= link->info->mci)
return;
port->name = "DUAL MCI";
port->type_name = "MCI";
@@ -1901,7 +1902,7 @@ static void ddb_port_probe(struct ddb_port *port)
return;
}
 
-   if (port->nr > 1 && dev->link[l].info->type == DDB_OCTOPUS_CI) {
+   if (port->nr > 1 && link->info->type == DDB_OCTOPUS_CI) {
port->name = "CI internal";
port->type_name = "INTERNAL";
port->class = DDB_PORT_CI;
@@ -1986,7 +1987,7 @@ static void ddb_port_probe(struct ddb_port *port)
port->class = DDB_PORT_TUNER;
if (id == 0x51) {
if (port->nr == 0 &&
-   dev->link[l].info->ts_quirks & TS_QUIRK_REVERSED)
+   link->info->ts_quirks & TS_QUIRK_REVERSED)
port->type = DDB_TUNER_DVBS_STV0910_PR;
else
port->type = DDB_TUNER_DVBS_STV0910_P;
-- 
2.16.4



[PATCH 19/19] [media] ddbridge/mci: add SX8 I/Q mode remark and remove DIAG CMD defines

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

Take note that the SX8 IQ mode is only available on a single tuner, and
remove the MCI/SX8 DIAG CMD defines.

Picked up from the upstream dddvb GIT.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-mci.h | 24 
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.h 
b/drivers/media/pci/ddbridge/ddbridge-mci.h
index 600a8bc642c4..2424c634 100644
--- a/drivers/media/pci/ddbridge/ddbridge-mci.h
+++ b/drivers/media/pci/ddbridge/ddbridge-mci.h
@@ -42,6 +42,22 @@
 #define SX8_TSCONFIG_MODE_NORMAL(0x0001)
 #define SX8_TSCONFIG_MODE_IQ(0x0003)
 
+/*
+ * IQMode is only available on MaxSX8 on a single tuner
+ *
+ * IQ_MODE_SAMPLES
+ *   sampling rate is 1550/24 MHz (64.583 MHz)
+ *   channel agc is frozen, to allow stitching the FFT results together
+ *
+ * IQ_MODE_VTM
+ *   sampling rate is the supplied symbolrate
+ *   channel agc is active
+ *
+ * in both cases down sampling is done with a RRC Filter (currently fixed to
+ * alpha = 0.05) which causes some (ca 5%) aliasing at the edges from
+ * outside the spectrum
+ */
+
 #define SX8_TSCONFIG_TSHEADER   (0x0004)
 #define SX8_TSCONFIG_BURST  (0x0008)
 
@@ -82,14 +98,6 @@
 
 #define MCI_SUCCESS(status)  ((status & MCI_STATUS_UNSUPPORTED) == 0)
 
-#define SX8_CMD_DIAG_READ8   (0xE0)
-#define SX8_CMD_DIAG_READ32  (0xE1)
-#define SX8_CMD_DIAG_WRITE8  (0xE2)
-#define SX8_CMD_DIAG_WRITE32 (0xE3)
-
-#define SX8_CMD_DIAG_READRF  (0xE8)
-#define SX8_CMD_DIAG_WRITERF (0xE9)
-
 struct mci_command {
union {
u32 command_word;
-- 
2.16.4



[PATCH 03/19] [media] ddbridge: probe for LNBH25 chips before attaching

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

In demod_attach_stv0910(), the LNBH25 IC is being blindly attached and,
if the result is bad, blindly attached on another possible I2C address.
The LNBH25 uses it's set_voltage function to test for the IC and will
print an error to the kernel log on failure. Prevent this by probing
the possible I2C address and use this (and only this) to attach the
LNBH25 I2C driver. This also allows the stv0910 attach function to be
a bit cleaner.

Picked up from the upstream dddvb GIT and adapted for the LNBH25 driver
variant from the kernel tree.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 22 +++---
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index d5b0d1eaf3ad..3f83415b06c7 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1191,6 +1191,13 @@ static const struct lnbh25_config lnbh25_cfg = {
.data2_config = LNBH25_TEN
 };
 
+static int has_lnbh25(struct i2c_adapter *i2c, u8 adr)
+{
+   u8 val;
+
+   return i2c_read_reg(i2c, adr, 0, &val) ? 0 : 1;
+}
+
 static int demod_attach_stv0910(struct ddb_input *input, int type, int tsfast)
 {
struct i2c_adapter *i2c = &input->port->i2c->adap;
@@ -1224,14 +1231,15 @@ static int demod_attach_stv0910(struct ddb_input 
*input, int type, int tsfast)
/* attach lnbh25 - leftshift by one as the lnbh25 driver expects 8bit
 * i2c addresses
 */
-   lnbcfg.i2c_address = (((input->nr & 1) ? 0x0d : 0x0c) << 1);
-   if (!dvb_attach(lnbh25_attach, dvb->fe, &lnbcfg, i2c)) {
+   if (has_lnbh25(i2c, 0x0d))
+   lnbcfg.i2c_address = (((input->nr & 1) ? 0x0d : 0x0c) << 1);
+   else
lnbcfg.i2c_address = (((input->nr & 1) ? 0x09 : 0x08) << 1);
-   if (!dvb_attach(lnbh25_attach, dvb->fe, &lnbcfg, i2c)) {
-   dev_err(dev, "No LNBH25 found!\n");
-   dvb_frontend_detach(dvb->fe);
-   return -ENODEV;
-   }
+
+   if (!dvb_attach(lnbh25_attach, dvb->fe, &lnbcfg, i2c)) {
+   dev_err(dev, "No LNBH25 found!\n");
+   dvb_frontend_detach(dvb->fe);
+   return -ENODEV;
}
 
return 0;
-- 
2.16.4



[PATCH 17/19] [media] ddbridge/sx8: disable automatic PLS code search

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

The SX8 cards by default do an automatic search for the PLS code. This
is not necessarily wanted as this can eventually be detected wrong, so
disable this.

Picked up from the upstream dddvb GIT.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-sx8.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-sx8.c 
b/drivers/media/pci/ddbridge/ddbridge-sx8.c
index 1a12f2105490..c87cefa10762 100644
--- a/drivers/media/pci/ddbridge/ddbridge-sx8.c
+++ b/drivers/media/pci/ddbridge/ddbridge-sx8.c
@@ -292,7 +292,7 @@ static int start(struct dvb_frontend *fe, u32 flags, u32 
modmask, u32 ts_config)
cmd.dvbs2_search.frequency = p->frequency * 1000;
cmd.dvbs2_search.symbol_rate = p->symbol_rate;
cmd.dvbs2_search.scrambling_sequence_index =
-   p->scrambling_sequence_index;
+   p->scrambling_sequence_index | 0x8000;
cmd.dvbs2_search.input_stream_id =
(p->stream_id != NO_STREAM_ID_FILTER) ? p->stream_id : 0;
cmd.tuner = state->mci.tuner;
-- 
2.16.4



[PATCH 15/19] [media] ddbridge/mci: split MaxSX8 specific code off to ddbridge-sx8.c

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

Split off all code specific to the MaxSX8 cards to a separate ddbridge-sx8
module and hook it up in the Makefile. This also adds evaluation of the
mci_type to allow for using different attach handling for different cards.
As different cards can implement things differently (ie. support differing
frontend_ops, and have different base structs being put ontop of the
common mci_base struct), this introduces the mci_cfg struct which is
initially used to hold a few specifics to the -sx8 submodule. While at it,
the handling of the i/q mode is adjusted slightly. Besides this and
handling mci_base and sx8_base struct pointers where needed, all code
is copied unmodified from ddbridge-mci.c.

Picked up from the upstream dddvb GIT.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/Makefile|   3 +-
 drivers/media/pci/ddbridge/ddbridge-core.c |   2 +-
 drivers/media/pci/ddbridge/ddbridge-max.c  |  18 +-
 drivers/media/pci/ddbridge/ddbridge-max.h  |   2 +-
 drivers/media/pci/ddbridge/ddbridge-mci.c  | 408 +
 drivers/media/pci/ddbridge/ddbridge-mci.h  |  28 +-
 drivers/media/pci/ddbridge/ddbridge-sx8.c  | 474 +
 7 files changed, 516 insertions(+), 419 deletions(-)
 create mode 100644 drivers/media/pci/ddbridge/ddbridge-sx8.c

diff --git a/drivers/media/pci/ddbridge/Makefile 
b/drivers/media/pci/ddbridge/Makefile
index 9b9e35f171b7..5b6d5bbc38af 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-max.o ddbridge-mci.o \
+   ddbridge-sx8.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 67b60da12cf4..c1b982e8e6c9 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1593,7 +1593,7 @@ static int dvb_input_attach(struct ddb_input *input)
goto err_detach;
break;
case DDB_TUNER_MCI_SX8:
-   if (ddb_fe_attach_mci(input) < 0)
+   if (ddb_fe_attach_mci(input, port->type) < 0)
goto err_detach;
break;
default:
diff --git a/drivers/media/pci/ddbridge/ddbridge-max.c 
b/drivers/media/pci/ddbridge/ddbridge-max.c
index 739e4b444cf4..8da1c7b91577 100644
--- a/drivers/media/pci/ddbridge/ddbridge-max.c
+++ b/drivers/media/pci/ddbridge/ddbridge-max.c
@@ -457,21 +457,29 @@ int ddb_fe_attach_mxl5xx(struct ddb_input *input)
 
/**/
 /* MAX MCI related functions */
 
-int ddb_fe_attach_mci(struct ddb_input *input)
+int ddb_fe_attach_mci(struct ddb_input *input, u32 type)
 {
struct ddb *dev = input->port->dev;
struct ddb_dvb *dvb = &input->port->dvb[input->nr & 1];
struct ddb_port *port = input->port;
struct ddb_link *link = &dev->link[port->lnr];
int demod, tuner;
+   struct mci_cfg cfg;
 
demod = input->nr;
tuner = demod & 3;
-   if (fmode == 3)
-   tuner = 0;
-   dvb->fe = ddb_mci_attach(input, 0, demod, &dvb->set_input);
+   switch (type) {
+   case DDB_TUNER_MCI_SX8:
+   cfg = ddb_max_sx8_cfg;
+   if (fmode == 3)
+   tuner = 0;
+   break;
+   default:
+   return -EINVAL;
+   }
+   dvb->fe = ddb_mci_attach(input, &cfg, demod, &dvb->set_input);
if (!dvb->fe) {
-   dev_err(dev->dev, "No MAXSX8 found!\n");
+   dev_err(dev->dev, "No MCI card found!\n");
return -ENODEV;
}
if (!dvb->set_input) {
diff --git a/drivers/media/pci/ddbridge/ddbridge-max.h 
b/drivers/media/pci/ddbridge/ddbridge-max.h
index 82efc53baa94..9838c73973b6 100644
--- a/drivers/media/pci/ddbridge/ddbridge-max.h
+++ b/drivers/media/pci/ddbridge/ddbridge-max.h
@@ -25,6 +25,6 @@
 
 int ddb_lnb_init_fmode(struct ddb *dev, struct ddb_link *link, u32 fm);
 int ddb_fe_attach_mxl5xx(struct ddb_input *input);
-int ddb_fe_attach_mci(struct ddb_input *input);
+int ddb_fe_attach_mci(struct ddb_input *input, u32 type);
 
 #endif /* _DDBRIDGE_MAX_H */
diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.c 
b/drivers/media/pci/ddbridge/ddbridge-mci.c
index a29ff25d9029..97384ae9ad27 100644
--- a/drivers/media/pci/ddbridge/ddbridge-mci.c
+++ b/drivers/media/pci/ddbridge/ddbridge-mci.c
@@ -22,10 +22,6 @@
 
 static LIST_HEAD(mci_list);
 
-static const u32 MCLK = (155000 / 12);
-static const u32 MAX_DEMOD_LDPC_BITRATE = (155000 / 6);
-static con

[PATCH 16/19] [media] ddbridge/mci: add more MCI status codes, improve MCI_SUCCESS macro

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

The MCI can report the command status more finegrained, so, add more
status code defines and update the MCI_SUCCESS macro.

Picked up from the upstream dddvb GIT.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-mci.h | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.h 
b/drivers/media/pci/ddbridge/ddbridge-mci.h
index f02bc76e3c98..600a8bc642c4 100644
--- a/drivers/media/pci/ddbridge/ddbridge-mci.h
+++ b/drivers/media/pci/ddbridge/ddbridge-mci.h
@@ -74,9 +74,13 @@
 #define SX8_CMD_ENABLE_IQOUTPUT  (0x44)
 #define SX8_CMD_DISABLE_IQOUTPUT (0x45)
 
-#define MCI_ERROR_UNSUPPORTED(0x80)
+#define MCI_STATUS_OK(0x00)
+#define MCI_STATUS_UNSUPPORTED   (0x80)
+#define MCI_STATUS_RETRY (0xFD)
+#define MCI_STATUS_NOT_READY (0xFE)
+#define MCI_STATUS_ERROR (0xFF)
 
-#define MCI_SUCCESS(status)  (status < MCI_ERROR_UNSUPPORTED)
+#define MCI_SUCCESS(status)  ((status & MCI_STATUS_UNSUPPORTED) == 0)
 
 #define SX8_CMD_DIAG_READ8   (0xE0)
 #define SX8_CMD_DIAG_READ32  (0xE1)
-- 
2.16.4



[PATCH 14/19] [media] ddbridge/mci: make ddb_mci_cmd() and ddb_mci_config() public

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

In preparation for splitting all MaxSX8 related code parts from the common
MCI code, prefix both mci_cmd() and mci_config() functions with ddb_,
remove the static marking and add matching function prototypes to
ddbridge-mci.h so these functions can be reused from other files within
the ddbridge driver. As this requires the mci-related structs to be
defined in ddbridge-mci.h, move struct mci and struct mci_base there and
clean them up.

Picked up from the upstream dddvb GIT.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-mci.c | 62 ---
 drivers/media/pci/ddbridge/ddbridge-mci.h | 36 ++
 2 files changed, 51 insertions(+), 47 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.c 
b/drivers/media/pci/ddbridge/ddbridge-mci.c
index fa0d7d0cc6f6..a29ff25d9029 100644
--- a/drivers/media/pci/ddbridge/ddbridge-mci.c
+++ b/drivers/media/pci/ddbridge/ddbridge-mci.c
@@ -26,38 +26,6 @@ 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[MCI_TUNER_MAX];
-   u8   assigned_demod[MCI_DEMOD_MAX];
-   u32  used_ldpc_bitrate[MCI_DEMOD_MAX];
-   u8   demod_in_use[MCI_DEMOD_MAX];
-   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;
@@ -84,7 +52,7 @@ static int mci_reset(struct mci *state)
return 0;
 }
 
-static int mci_config(struct mci *state, u32 config)
+int ddb_mci_config(struct mci *state, u32 config)
 {
struct ddb_link *link = state->base->link;
 
@@ -122,9 +90,9 @@ static int _mci_cmd_unlocked(struct mci *state,
return 0;
 }
 
-static int mci_cmd(struct mci *state,
-  struct mci_command *command,
-  struct mci_result *result)
+int ddb_mci_cmd(struct mci *state,
+   struct mci_command *command,
+   struct mci_result *result)
 {
int stat;
 
@@ -164,7 +132,7 @@ static int get_info(struct dvb_frontend *fe)
memset(&cmd, 0, sizeof(cmd));
cmd.command = MCI_CMD_GETSIGNALINFO;
cmd.demod = state->demod;
-   stat = mci_cmd(state, &cmd, &state->signal_info);
+   stat = ddb_mci_cmd(state, &cmd, &state->signal_info);
return stat;
 }
 
@@ -205,7 +173,7 @@ static int read_status(struct dvb_frontend *fe, enum 
fe_status *status)
 
cmd.command = MCI_CMD_GETSTATUS;
cmd.demod = state->demod;
-   stat = mci_cmd(state, &cmd, &res);
+   stat = ddb_mci_cmd(state, &cmd, &res);
if (stat)
return stat;
*status = 0x00;
@@ -228,7 +196,7 @@ static int mci_set_tuner(struct dvb_frontend *fe, u32 
tuner, u32 on)
memset(&cmd, 0, sizeof(cmd));
cmd.tuner = state->tuner;
cmd.command = on ? SX8_CMD_INPUT_ENABLE : SX8_CMD_INPUT_DISABLE;
-   return mci_cmd(state, &cmd, NULL);
+   return ddb_mci_cmd(state, &cmd, NULL);
 }
 
 static int stop(struct dvb_frontend *fe)
@@ -241,13 +209,13 @@ static int stop(struct dvb_frontend *fe)
if (state->demod != DEMOD_UNUSED) {
cmd.command = MCI_CMD_STOP;
cmd.demod = state->demod;
-   mci_cmd(state, &cmd, NULL);
+   ddb_mci_cmd(state, &cmd, NULL);
if (state->base->iq_mode) {
cmd.command = MCI_CMD_STOP;
cmd.demod = state->demod;
cmd.output = 0;
-   mci_cmd(state, &cmd, NULL);
-   mci_config(state, SX8_TSCONFIG_MODE_NORMAL);
+   ddb_mci_cmd(state, &cmd, NULL);
+   ddb_mci_config(state, SX8_TSCONFIG_MODE_NORMAL);
}
}
mutex_lock(&state->base->tuner_lock);
@@ -345,8 +313,8 @@ static int start(struct dvb_frontend *fe, u32 flags, u32 
modmask, u32 ts_config)
   

[PATCH 06/19] [media] ddbridge: remove unused MDIO defines and hwinfo member

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

ddbridge has a few MDIO related remainders (defines, hwinfo struct) which
aren't of any use for the in-kernel driver at all (they're only used in
conjunction with the OctoNet SAT>IP boxes which the kernel driver doesn't
have any support for), so clean this up.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-regs.h | 8 
 drivers/media/pci/ddbridge/ddbridge.h  | 1 -
 2 files changed, 9 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-regs.h 
b/drivers/media/pci/ddbridge/ddbridge-regs.h
index b978b5991940..f9e1cbb99b53 100644
--- a/drivers/media/pci/ddbridge/ddbridge-regs.h
+++ b/drivers/media/pci/ddbridge/ddbridge-regs.h
@@ -33,14 +33,6 @@
 #define GPIO_INPUT   0x24
 #define GPIO_DIRECTION   0x28
 
-/* - */
-/* MDIO */
-
-#define MDIO_CTRL0x20
-#define MDIO_ADR 0x24
-#define MDIO_REG 0x28
-#define MDIO_VAL 0x2C
-
 /* - */
 
 #define BOARD_CONTROL0x30
diff --git a/drivers/media/pci/ddbridge/ddbridge.h 
b/drivers/media/pci/ddbridge/ddbridge.h
index a66b1125cc74..9c645bee428a 100644
--- a/drivers/media/pci/ddbridge/ddbridge.h
+++ b/drivers/media/pci/ddbridge/ddbridge.h
@@ -127,7 +127,6 @@ struct ddb_info {
u8temp_bus;
u32   board_control;
u32   board_control_2;
-   u8mdio_num;
u8con_clock; /* use a continuous clock */
u8ts_quirks;
 #define TS_QUIRK_SERIAL   1
-- 
2.16.4



[PATCH 11/19] [media] ddbridge/mci: rename defines and fix i/q var types

2018-06-23 Thread Daniel Scheller
From: Daniel Scheller 

Adjustments to match the FPGA firmware, and the signal I/Q values are
reported as s16 types from the card firmware.

Picked up from the upstream dddvb GIT.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-mci.c |  2 +-
 drivers/media/pci/ddbridge/ddbridge-mci.h | 56 +++
 2 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.c 
b/drivers/media/pci/ddbridge/ddbridge-mci.c
index 7d402861fa9e..fa0d7d0cc6f6 100644
--- a/drivers/media/pci/ddbridge/ddbridge-mci.c
+++ b/drivers/media/pci/ddbridge/ddbridge-mci.c
@@ -342,7 +342,7 @@ static int start(struct dvb_frontend *fe, u32 flags, u32 
modmask, u32 ts_config)
memset(&cmd, 0, sizeof(cmd));
 
if (state->base->iq_mode) {
-   cmd.command = SX8_CMD_SELECT_IQOUT;
+   cmd.command = SX8_CMD_ENABLE_IQOUTPUT;
cmd.demod = state->demod;
cmd.output = 0;
mci_cmd(state, &cmd, NULL);
diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.h 
b/drivers/media/pci/ddbridge/ddbridge-mci.h
index 389f6376603b..2e74f0544717 100644
--- a/drivers/media/pci/ddbridge/ddbridge-mci.h
+++ b/drivers/media/pci/ddbridge/ddbridge-mci.h
@@ -51,40 +51,40 @@
 #define SX8_TSCONFIG_BURSTSIZE_8K   (0x0020)
 #define SX8_TSCONFIG_BURSTSIZE_16K  (0x0030)
 
-#define SX8_DEMOD_STOPPED   (0)
-#define SX8_DEMOD_IQ_MODE   (1)
-#define SX8_DEMOD_WAIT_SIGNAL   (2)
-#define SX8_DEMOD_WAIT_MATYPE   (3)
-#define SX8_DEMOD_TIMEOUT   (14)
-#define SX8_DEMOD_LOCKED(15)
+#define SX8_DEMOD_STOPPED(0)
+#define SX8_DEMOD_IQ_MODE(1)
+#define SX8_DEMOD_WAIT_SIGNAL(2)
+#define SX8_DEMOD_WAIT_MATYPE(3)
+#define SX8_DEMOD_TIMEOUT(14)
+#define SX8_DEMOD_LOCKED (15)
 
-#define MCI_CMD_STOP(0x01)
-#define MCI_CMD_GETSTATUS   (0x02)
-#define MCI_CMD_GETSIGNALINFO   (0x03)
-#define MCI_CMD_RFPOWER (0x04)
+#define MCI_CMD_STOP (0x01)
+#define MCI_CMD_GETSTATUS(0x02)
+#define MCI_CMD_GETSIGNALINFO(0x03)
+#define MCI_CMD_RFPOWER  (0x04)
 
-#define MCI_CMD_SEARCH_DVBS (0x10)
+#define MCI_CMD_SEARCH_DVBS  (0x10)
 
-#define MCI_CMD_GET_IQSYMBOL(0x30)
+#define MCI_CMD_GET_IQSYMBOL (0x30)
 
-#define SX8_CMD_INPUT_ENABLE(0x40)
-#define SX8_CMD_INPUT_DISABLE   (0x41)
-#define SX8_CMD_START_IQ(0x42)
-#define SX8_CMD_STOP_IQ (0x43)
-#define SX8_CMD_SELECT_IQOUT(0x44)
-#define SX8_CMD_SELECT_TSOUT(0x45)
+#define SX8_CMD_INPUT_ENABLE (0x40)
+#define SX8_CMD_INPUT_DISABLE(0x41)
+#define SX8_CMD_START_IQ (0x42)
+#define SX8_CMD_STOP_IQ  (0x43)
+#define SX8_CMD_ENABLE_IQOUTPUT  (0x44)
+#define SX8_CMD_DISABLE_IQOUTPUT (0x45)
 
-#define SX8_ERROR_UNSUPPORTED   (0x80)
+#define MCI_ERROR_UNSUPPORTED(0x80)
 
-#define SX8_SUCCESS(status) (status < SX8_ERROR_UNSUPPORTED)
+#define MCI_SUCCESS(status)  (status < MCI_ERROR_UNSUPPORTED)
 
-#define SX8_CMD_DIAG_READ8  (0xE0)
-#define SX8_CMD_DIAG_READ32 (0xE1)
-#define SX8_CMD_DIAG_WRITE8 (0xE2)
-#define SX8_CMD_DIAG_WRITE32(0xE3)
+#define SX8_CMD_DIAG_READ8   (0xE0)
+#define SX8_CMD_DIAG_READ32  (0xE1)
+#define SX8_CMD_DIAG_WRITE8  (0xE2)
+#define SX8_CMD_DIAG_WRITE32 (0xE3)
 
-#define SX8_CMD_DIAG_READRF (0xE8)
-#define SX8_CMD_DIAG_WRITERF(0xE9)
+#define SX8_CMD_DIAG_READRF  (0xE8)
+#define SX8_CMD_DIAG_WRITERF (0xE9)
 
 struct mci_command {
union {
@@ -141,8 +141,8 @@ struct mci_result {
u32 ber_denominator;
} dvbs2_signal_info;
struct {
-   u8 i_symbol;
-   u8 q_symbol;
+   s16 i;
+   s16 q;
} dvbs2_signal_iq;
};
u32 version[4];
-- 
2.16.4



[PATCH] [media] dvb-frontends/tda18271c2dd: silence sparse fall through warning

2018-06-24 Thread Daniel Scheller
From: Daniel Scheller 

Add a break statement in set_params() for the SYS_DVBT(2) case to silence
this sparse warning:

drivers/media/dvb-frontends/tda18271c2dd.c:1144:3: warning: this statement 
may fall through [-Wimplicit-fallthrough=]

as reported in Hans' daily media_tree builds.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/tda18271c2dd.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/dvb-frontends/tda18271c2dd.c 
b/drivers/media/dvb-frontends/tda18271c2dd.c
index 2e1d36ae943b..fcffc7b4acf7 100644
--- a/drivers/media/dvb-frontends/tda18271c2dd.c
+++ b/drivers/media/dvb-frontends/tda18271c2dd.c
@@ -1154,6 +1154,7 @@ static int set_params(struct dvb_frontend *fe)
default:
return -EINVAL;
}
+   break;
case SYS_DVBC_ANNEX_A:
case SYS_DVBC_ANNEX_C:
if (bw <= 600)
-- 
2.16.4



Re: [PATCH v3 0/3] IOCTLs in ddbridge.

2018-07-04 Thread Daniel Scheller
Am Wed, 4 Jul 2018 13:08:31 -0300
schrieb Mauro Carvalho Chehab :

> Em Sat, 12 May 2018 13:24:29 +0200
> Daniel Scheller  escreveu:
> 
> > From: Daniel Scheller 
> > 
> > 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


[PATCH 19/20] [media] ddbridge: recognize and attach the MaxSX8 cards

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

Add needed logic into dvb_input_attach(), ddb_port_probe() and
ddb_ports_init() to initialize and support these new cards.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 59e137516003..4a2819d3e225 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -1574,6 +1574,10 @@ static int dvb_input_attach(struct ddb_input *input)
if (demod_attach_dummy(input) < 0)
goto err_detach;
break;
+   case DDB_TUNER_MCI:
+   if (ddb_fe_attach_mci(input) < 0)
+   goto err_detach;
+   break;
default:
return 0;
}
@@ -1869,6 +1873,16 @@ static void ddb_port_probe(struct ddb_port *port)
return;
}
 
+   if (dev->link[l].info->type == DDB_OCTOPUS_MCI) {
+   if (port->nr >= dev->link[l].info->mci)
+   return;
+   port->name = "DUAL MCI";
+   port->type_name = "MCI";
+   port->class = DDB_PORT_TUNER;
+   port->type = DDB_TUNER_MCI;
+   return;
+   }
+
if (port->nr > 1 && dev->link[l].info->type == DDB_OCTOPUS_CI) {
port->name = "CI internal";
port->type_name = "INTERNAL";
@@ -2411,6 +2425,7 @@ void ddb_ports_init(struct ddb *dev)
break;
case DDB_OCTOPUS_MAX:
case DDB_OCTOPUS_MAX_CT:
+   case DDB_OCTOPUS_MCI:
ddb_input_init(port, 2 * i, 0, 2 * p);
ddb_input_init(port, 2 * i + 1, 1, 2 * p + 1);
break;
-- 
2.16.1



[PATCH 02/20] [media] dvb-frontends/stv0910: increase parallel TS output speed

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

When running in parallel TS mode (cfg->parallel=1), increase the output
speed in the demod.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0910.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index f5b5ce971c0c..0d6130f97c36 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -1200,7 +1200,6 @@ static int probe(struct stv *state)
write_reg(state, RSTV0910_P1_TSCFGM, 0xC0); /* Manual speed */
write_reg(state, RSTV0910_P1_TSCFGL, 0x20);
 
-   /* Speed = 67.5 MHz */
write_reg(state, RSTV0910_P1_TSSPEED, state->tsspeed);
 
write_reg(state, RSTV0910_P2_TSCFGH, state->tscfgh | 0x01);
@@ -1208,7 +1207,6 @@ static int probe(struct stv *state)
write_reg(state, RSTV0910_P2_TSCFGM, 0xC0); /* Manual speed */
write_reg(state, RSTV0910_P2_TSCFGL, 0x20);
 
-   /* Speed = 67.5 MHz */
write_reg(state, RSTV0910_P2_TSSPEED, state->tsspeed);
 
/* Reset stream merger */
@@ -1790,7 +1788,7 @@ struct dvb_frontend *stv0910_attach(struct i2c_adapter 
*i2c,
state->tscfgh = 0x20 | (cfg->parallel ? 0 : 0x40);
state->tsgeneral = (cfg->parallel == 2) ? 0x02 : 0x00;
state->i2crpt = 0x0A | ((cfg->rptlvl & 0x07) << 4);
-   state->tsspeed = 0x28;
+   state->tsspeed = cfg->parallel ? 0x10 : 0x28;
state->nr = nr;
state->regoff = state->nr ? 0 : 0x200;
state->search_range = 1600;
-- 
2.16.1



[PATCH 04/20] [media] ddbridge: move modparams to ddbridge-core.c

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

Besides the 'msi' module option, all options are used from within
ddbridge-core only, so move them over from ddbridge-main, and declare the
associated variables static. Since the prototypes in ddbridge.h aren't
necessary anymore now, remove them. As a side effect, this has the benefit
of aligning things more with the dddvb upstream.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 28 
 drivers/media/pci/ddbridge/ddbridge-main.c | 28 
 drivers/media/pci/ddbridge/ddbridge.h  |  6 --
 3 files changed, 28 insertions(+), 34 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 90687eff5909..933046d03db5 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -68,6 +68,34 @@ module_param(adapter_alloc, int, 0444);
 MODULE_PARM_DESC(adapter_alloc,
 "0-one adapter per io, 1-one per tab with io, 2-one per tab, 
3-one for all");
 
+static int ci_bitrate = 7;
+module_param(ci_bitrate, int, 0444);
+MODULE_PARM_DESC(ci_bitrate, " Bitrate in KHz for output to CI.");
+
+static int ts_loop = -1;
+module_param(ts_loop, int, 0444);
+MODULE_PARM_DESC(ts_loop, "TS in/out test loop on port ts_loop");
+
+static int xo2_speed = 2;
+module_param(xo2_speed, int, 0444);
+MODULE_PARM_DESC(xo2_speed, "default transfer speed for xo2 based duoflex, 
0=55,1=75,2=90,3=104 MBit/s, default=2, use attribute to change for individual 
cards");
+
+#ifdef __arm__
+static int alt_dma = 1;
+#else
+static int alt_dma;
+#endif
+module_param(alt_dma, int, 0444);
+MODULE_PARM_DESC(alt_dma, "use alternative DMA buffer handling");
+
+static int no_init;
+module_param(no_init, int, 0444);
+MODULE_PARM_DESC(no_init, "do not initialize most devices");
+
+static int stv0910_single;
+module_param(stv0910_single, int, 0444);
+MODULE_PARM_DESC(stv0910_single, "use stv0910 cards as single demods");
+
 //
 
 static DEFINE_MUTEX(redirect_lock);
diff --git a/drivers/media/pci/ddbridge/ddbridge-main.c 
b/drivers/media/pci/ddbridge/ddbridge-main.c
index 26497d6b1395..bde04dc39080 100644
--- a/drivers/media/pci/ddbridge/ddbridge-main.c
+++ b/drivers/media/pci/ddbridge/ddbridge-main.c
@@ -55,34 +55,6 @@ MODULE_PARM_DESC(msi, "Control MSI interrupts: 0-disable 
(default), 1-enable");
 #endif
 #endif
 
-int ci_bitrate = 7;
-module_param(ci_bitrate, int, 0444);
-MODULE_PARM_DESC(ci_bitrate, " Bitrate in KHz for output to CI.");
-
-int ts_loop = -1;
-module_param(ts_loop, int, 0444);
-MODULE_PARM_DESC(ts_loop, "TS in/out test loop on port ts_loop");
-
-int xo2_speed = 2;
-module_param(xo2_speed, int, 0444);
-MODULE_PARM_DESC(xo2_speed, "default transfer speed for xo2 based duoflex, 
0=55,1=75,2=90,3=104 MBit/s, default=2, use attribute to change for individual 
cards");
-
-#ifdef __arm__
-int alt_dma = 1;
-#else
-int alt_dma;
-#endif
-module_param(alt_dma, int, 0444);
-MODULE_PARM_DESC(alt_dma, "use alternative DMA buffer handling");
-
-int no_init;
-module_param(no_init, int, 0444);
-MODULE_PARM_DESC(no_init, "do not initialize most devices");
-
-int stv0910_single;
-module_param(stv0910_single, int, 0444);
-MODULE_PARM_DESC(stv0910_single, "use stv0910 cards as single demods");
-
 //
 //
 //
diff --git a/drivers/media/pci/ddbridge/ddbridge.h 
b/drivers/media/pci/ddbridge/ddbridge.h
index f223dc6c9963..e22e67d7e0fe 100644
--- a/drivers/media/pci/ddbridge/ddbridge.h
+++ b/drivers/media/pci/ddbridge/ddbridge.h
@@ -369,12 +369,6 @@ int ddbridge_flashread(struct ddb *dev, u32 link, u8 *buf, 
u32 addr, u32 len);
 //
 
 /* ddbridge-main.c (modparams) */
-extern int ci_bitrate;
-extern int ts_loop;
-extern int xo2_speed;
-extern int alt_dma;
-extern int no_init;
-extern int stv0910_single;
 extern struct workqueue_struct *ddb_wq;
 
 /* ddbridge-core.c */
-- 
2.16.1



[PATCH 15/20] [media] ddbridge: support dummy tuners with 125MByte/s dummy data stream

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

The Octopus V3 and Octopus Mini devices support set up of a dummy tuner
mode on port 0 that will deliver a continuous data stream of 125MBytes
per second while raising IRQs and filling the DMA buffers, which comes
handy for some stress, PCIe link and IRQ handling testing. The dummy
frontend is registered using dvb_dummy_fe's QAM dummy frontend. Set
ddbridge.dummy_tuner to 1 to enable this on the supported cards.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/Kconfig |  1 +
 drivers/media/pci/ddbridge/ddbridge-core.c | 36 ++
 drivers/media/pci/ddbridge/ddbridge.h  |  1 +
 3 files changed, 38 insertions(+)

diff --git a/drivers/media/pci/ddbridge/Kconfig 
b/drivers/media/pci/ddbridge/Kconfig
index a422dde2f34a..16faef265e97 100644
--- a/drivers/media/pci/ddbridge/Kconfig
+++ b/drivers/media/pci/ddbridge/Kconfig
@@ -14,6 +14,7 @@ config DVB_DDBRIDGE
select MEDIA_TUNER_TDA18212 if MEDIA_SUBDRV_AUTOSELECT
select DVB_MXL5XX if MEDIA_SUBDRV_AUTOSELECT
select DVB_CXD2099 if MEDIA_SUBDRV_AUTOSELECT
+   select DVB_DUMMY_FE if MEDIA_SUBDRV_AUTOSELECT
---help---
  Support for cards with the Digital Devices PCI express bridge:
  - Octopus PCIe Bridge
diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 8907551b02e4..59e137516003 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -54,6 +54,7 @@
 #include "stv6111.h"
 #include "lnbh25.h"
 #include "cxd2099.h"
+#include "dvb_dummy_fe.h"
 
 //
 
@@ -105,6 +106,11 @@ module_param(dma_buf_size, int, 0444);
 MODULE_PARM_DESC(dma_buf_size,
 "DMA buffer size as multiple of 128*47, possible values: 
1-43");
 
+static int dummy_tuner;
+module_param(dummy_tuner, int, 0444);
+MODULE_PARM_DESC(dummy_tuner,
+"attach dummy tuner to port 0 on Octopus V3 or Octopus Mini 
cards");
+
 //
 
 static DEFINE_MUTEX(redirect_lock);
@@ -548,6 +554,9 @@ static void ddb_input_start(struct ddb_input *input)
 
ddbwritel(dev, 0x09, TS_CONTROL(input));
 
+   if (input->port->type == DDB_TUNER_DUMMY)
+   ddbwritel(dev, 0x000fff01, TS_CONTROL2(input));
+
if (input->dma) {
input->dma->running = 1;
spin_unlock_irq(&input->dma->lock);
@@ -1255,6 +1264,20 @@ static int tuner_attach_stv6111(struct ddb_input *input, 
int type)
return 0;
 }
 
+static int demod_attach_dummy(struct ddb_input *input)
+{
+   struct ddb_dvb *dvb = &input->port->dvb[input->nr & 1];
+   struct device *dev = input->port->dev->dev;
+
+   dvb->fe = dvb_attach(dvb_dummy_fe_qam_attach);
+   if (!dvb->fe) {
+   dev_err(dev, "QAM dummy attach failed!\n");
+   return -ENODEV;
+   }
+
+   return 0;
+}
+
 static int start_feed(struct dvb_demux_feed *dvbdmxfeed)
 {
struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
@@ -1547,6 +1570,10 @@ static int dvb_input_attach(struct ddb_input *input)
if (tuner_attach_tda18212(input, port->type) < 0)
goto err_tuner;
break;
+   case DDB_TUNER_DUMMY:
+   if (demod_attach_dummy(input) < 0)
+   goto err_detach;
+   break;
default:
return 0;
}
@@ -1809,6 +1836,15 @@ static void ddb_port_probe(struct ddb_port *port)
 
/* Handle missing ports and ports without I2C */
 
+   if (dummy_tuner && !port->nr &&
+   dev->link[0].ids.device == 0x0005) {
+   port->name = "DUMMY";
+   port->class = DDB_PORT_TUNER;
+   port->type = DDB_TUNER_DUMMY;
+   port->type_name = "DUMMY";
+   return;
+   }
+
if (port->nr == ts_loop) {
port->name = "TS LOOP";
port->class = DDB_PORT_LOOP;
diff --git a/drivers/media/pci/ddbridge/ddbridge.h 
b/drivers/media/pci/ddbridge/ddbridge.h
index 86db6f19369a..cb69021a3443 100644
--- a/drivers/media/pci/ddbridge/ddbridge.h
+++ b/drivers/media/pci/ddbridge/ddbridge.h
@@ -236,6 +236,7 @@ struct ddb_port {
char   *name;
char   *type_name;
u32 type;
+#define DDB_TUNER_DUMMY  0x
 #define DDB_TUNER_NONE   0
 #define DDB_TUNER_DVBS_ST1
 #define DDB_TUNER_DVBS_ST_AA 2
-- 
2.16.1



[PATCH 09/20] [media] ddbridge: add macros to handle IRQs in nibble and byte blocks

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

Currently, each IRQ requires one IRQ_HANDLE() line to call each IRQ
handler that was set up. Add a IRQ_HANDLE_NIBBLE() and IRQ_HANDLE_BYTE()
macro to call all handlers in blocks of four (_NIBBLE) or eight (_BYTE)
handlers at a time, to make this construct more compact.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 67 --
 1 file changed, 27 insertions(+), 40 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index be6935bd0cb5..5fbb0996a12c 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -2403,54 +2403,41 @@ void ddb_ports_release(struct ddb *dev)
dev->link[0].irq[_nr].handler(dev->link[0].irq[_nr].data); } \
while (0)
 
+#define IRQ_HANDLE_NIBBLE(_shift) { \
+   if (s & (0x000f << ((_shift) & 0x1f))) { \
+   IRQ_HANDLE(0 + (_shift));\
+   IRQ_HANDLE(1 + (_shift));\
+   IRQ_HANDLE(2 + (_shift));\
+   IRQ_HANDLE(3 + (_shift));\
+   }\
+}
+
+#define IRQ_HANDLE_BYTE(_shift) {   \
+   if (s & (0x00ff << ((_shift) & 0x1f))) { \
+   IRQ_HANDLE(0 + (_shift));\
+   IRQ_HANDLE(1 + (_shift));\
+   IRQ_HANDLE(2 + (_shift));\
+   IRQ_HANDLE(3 + (_shift));\
+   IRQ_HANDLE(4 + (_shift));\
+   IRQ_HANDLE(5 + (_shift));\
+   IRQ_HANDLE(6 + (_shift));\
+   IRQ_HANDLE(7 + (_shift));\
+   }\
+}
+
 static void irq_handle_msg(struct ddb *dev, u32 s)
 {
dev->i2c_irq++;
-   IRQ_HANDLE(0);
-   IRQ_HANDLE(1);
-   IRQ_HANDLE(2);
-   IRQ_HANDLE(3);
+   IRQ_HANDLE_NIBBLE(0);
 }
 
 static void irq_handle_io(struct ddb *dev, u32 s)
 {
dev->ts_irq++;
-   if ((s & 0x00f0)) {
-   IRQ_HANDLE(4);
-   IRQ_HANDLE(5);
-   IRQ_HANDLE(6);
-   IRQ_HANDLE(7);
-   }
-   if ((s & 0xff00)) {
-   IRQ_HANDLE(8);
-   IRQ_HANDLE(9);
-   IRQ_HANDLE(10);
-   IRQ_HANDLE(11);
-   IRQ_HANDLE(12);
-   IRQ_HANDLE(13);
-   IRQ_HANDLE(14);
-   IRQ_HANDLE(15);
-   }
-   if ((s & 0x00ff)) {
-   IRQ_HANDLE(16);
-   IRQ_HANDLE(17);
-   IRQ_HANDLE(18);
-   IRQ_HANDLE(19);
-   IRQ_HANDLE(20);
-   IRQ_HANDLE(21);
-   IRQ_HANDLE(22);
-   IRQ_HANDLE(23);
-   }
-   if ((s & 0xff00)) {
-   IRQ_HANDLE(24);
-   IRQ_HANDLE(25);
-   IRQ_HANDLE(26);
-   IRQ_HANDLE(27);
-   IRQ_HANDLE(28);
-   IRQ_HANDLE(29);
-   IRQ_HANDLE(30);
-   IRQ_HANDLE(31);
-   }
+   IRQ_HANDLE_NIBBLE(4);
+   IRQ_HANDLE_BYTE(8);
+   IRQ_HANDLE_BYTE(16);
+   IRQ_HANDLE_BYTE(24);
 }
 
 irqreturn_t ddb_irq_handler0(int irq, void *dev_id)
-- 
2.16.1



[PATCH 12/20] [media] ddbridge: fix output buffer check

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

A 188 byte gap has to be left between the writer and the consumer. This
requires 2*188 bytes available to be able to write to the output buffers.
So, change ddb_output_free() to report free bytes according to this rule.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index c22537eceee5..e9c2e3e5d64b 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -587,12 +587,12 @@ static u32 ddb_output_free(struct ddb_output *output)
 
if (output->dma->cbuf != idx) {
if output->dma->cbuf + 1) % output->dma->num) == idx) &&
-   (output->dma->size - output->dma->coff <= 188))
+   (output->dma->size - output->dma->coff <= (2 * 188)))
return 0;
return 188;
}
diff = off - output->dma->coff;
-   if (diff <= 0 || diff > 188)
+   if (diff <= 0 || diff > (2 * 188))
return 188;
return 0;
 }
-- 
2.16.1



[PATCH 03/20] [media] dvb-frontends/stv0910: fix CNR reporting in read_snr()

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

The CNR value determined in read_snr() is reported via the wrong variable.
It uses FE_SCALE_DECIBEL, which implies the value to be reported in svalue
instead of uvalue. Fix this accordingly.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0910.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index 0d6130f97c36..e3d939933d6e 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -1324,7 +1324,7 @@ static int read_snr(struct dvb_frontend *fe)
 
if (!get_signal_to_noise(state, &snrval)) {
p->cnr.stat[0].scale = FE_SCALE_DECIBEL;
-   p->cnr.stat[0].uvalue = 100 * snrval; /* fix scale */
+   p->cnr.stat[0].svalue = 100 * snrval; /* fix scale */
} else {
p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
}
-- 
2.16.1



[PATCH 10/20] [media] ddbridge: improve separated MSI IRQ handling

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

Improve IRQ handling in the separated MSG/I2C and IO/TSDATA handlers by
applying a mask for recognized bits immediately upon reading the IRQ mask
from the hardware, so only the bits/IRQs that actually were set will be
acked.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 5fbb0996a12c..9d91221dacc4 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -2443,16 +2443,17 @@ static void irq_handle_io(struct ddb *dev, u32 s)
 irqreturn_t ddb_irq_handler0(int irq, void *dev_id)
 {
struct ddb *dev = (struct ddb *)dev_id;
-   u32 s = ddbreadl(dev, INTERRUPT_STATUS);
+   u32 mask = 0x8f00;
+   u32 s = mask & ddbreadl(dev, INTERRUPT_STATUS);
 
+   if (!s)
+   return IRQ_NONE;
do {
if (s & 0x8000)
return IRQ_NONE;
-   if (!(s & 0xf00))
-   return IRQ_NONE;
-   ddbwritel(dev, s & 0xf00, INTERRUPT_ACK);
+   ddbwritel(dev, s, INTERRUPT_ACK);
irq_handle_io(dev, s);
-   } while ((s = ddbreadl(dev, INTERRUPT_STATUS)));
+   } while ((s = mask & ddbreadl(dev, INTERRUPT_STATUS)));
 
return IRQ_HANDLED;
 }
@@ -2460,16 +2461,17 @@ irqreturn_t ddb_irq_handler0(int irq, void *dev_id)
 irqreturn_t ddb_irq_handler1(int irq, void *dev_id)
 {
struct ddb *dev = (struct ddb *)dev_id;
-   u32 s = ddbreadl(dev, INTERRUPT_STATUS);
+   u32 mask = 0x800f;
+   u32 s = mask & ddbreadl(dev, INTERRUPT_STATUS);
 
+   if (!s)
+   return IRQ_NONE;
do {
if (s & 0x8000)
return IRQ_NONE;
-   if (!(s & 0xf))
-   return IRQ_NONE;
-   ddbwritel(dev, s & 0xf, INTERRUPT_ACK);
+   ddbwritel(dev, s, INTERRUPT_ACK);
irq_handle_msg(dev, s);
-   } while ((s = ddbreadl(dev, INTERRUPT_STATUS)));
+   } while ((s = mask & ddbreadl(dev, INTERRUPT_STATUS)));
 
return IRQ_HANDLED;
 }
-- 
2.16.1



[PATCH 06/20] [media] ddbridge: move MSI IRQ cleanup to a helper function

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

Introduce the ddb_msi_exit() helper to be used for cleaning up previously
allocated MSI IRQ vectors. Deduplicates code and makes things look
cleaner as for all cleanup work the CONFIG_PCI_MSI ifdeffery is only
needed in the helper now. Also, replace the call to the deprecated
pci_disable_msi() function with pci_free_irq_vectors().

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-main.c | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-main.c 
b/drivers/media/pci/ddbridge/ddbridge-main.c
index 7088162af9d3..77089081db1f 100644
--- a/drivers/media/pci/ddbridge/ddbridge-main.c
+++ b/drivers/media/pci/ddbridge/ddbridge-main.c
@@ -65,16 +65,20 @@ static void ddb_irq_disable(struct ddb *dev)
ddbwritel(dev, 0, MSI1_ENABLE);
 }
 
+static void ddb_msi_exit(struct ddb *dev)
+{
+#ifdef CONFIG_PCI_MSI
+   if (dev->msi)
+   pci_free_irq_vectors(dev->pdev);
+#endif
+}
+
 static void ddb_irq_exit(struct ddb *dev)
 {
ddb_irq_disable(dev);
if (dev->msi == 2)
free_irq(dev->pdev->irq + 1, dev);
free_irq(dev->pdev->irq, dev);
-#ifdef CONFIG_PCI_MSI
-   if (dev->msi)
-   pci_disable_msi(dev->pdev);
-#endif
 }
 
 static void ddb_remove(struct pci_dev *pdev)
@@ -86,6 +90,7 @@ static void ddb_remove(struct pci_dev *pdev)
ddb_i2c_release(dev);
 
ddb_irq_exit(dev);
+   ddb_msi_exit(dev);
ddb_ports_release(dev);
ddb_buffers_free(dev);
 
@@ -230,8 +235,7 @@ static int ddb_probe(struct pci_dev *pdev,
ddb_irq_exit(dev);
 fail0:
dev_err(&pdev->dev, "fail0\n");
-   if (dev->msi)
-   pci_disable_msi(dev->pdev);
+   ddb_msi_exit(dev);
 fail:
dev_err(&pdev->dev, "fail\n");
 
-- 
2.16.1



[PATCH 16/20] [media] ddbridge: initial support for MCI-based MaxSX8 cards

2018-04-02 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 mci_config(struct mc

[PATCH 20/20] [media] ddbridge: set driver version to 0.9.33-integrated

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

Set DDBRIDGE_VERSION in ddbridge.h to 0.9.33-integrated to reflect the
updated driver.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge.h 
b/drivers/media/pci/ddbridge/ddbridge.h
index 72fe33cb72b9..a66b1125cc74 100644
--- a/drivers/media/pci/ddbridge/ddbridge.h
+++ b/drivers/media/pci/ddbridge/ddbridge.h
@@ -63,7 +63,7 @@
 #include 
 #include 
 
-#define DDBRIDGE_VERSION "0.9.32-integrated"
+#define DDBRIDGE_VERSION "0.9.33-integrated"
 
 #define DDB_MAX_I2C32
 #define DDB_MAX_PORT   32
-- 
2.16.1



[PATCH 07/20] [media] ddbridge: request/free_irq using pci_irq_vector, enable MSI-X

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

Instead of trying to manage IRQ numbers on itself, utilise the
pci_irq_vector() function to do this, which will take care of correct IRQ
numbering for MSI and non-MSI IRQs. While at it, request and enable MSI-X
interrupts for hardware (boards and cards) that support this.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-main.c | 24 ++--
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-main.c 
b/drivers/media/pci/ddbridge/ddbridge-main.c
index 77089081db1f..008be9066814 100644
--- a/drivers/media/pci/ddbridge/ddbridge-main.c
+++ b/drivers/media/pci/ddbridge/ddbridge-main.c
@@ -77,8 +77,8 @@ static void ddb_irq_exit(struct ddb *dev)
 {
ddb_irq_disable(dev);
if (dev->msi == 2)
-   free_irq(dev->pdev->irq + 1, dev);
-   free_irq(dev->pdev->irq, dev);
+   free_irq(pci_irq_vector(dev->pdev, 1), dev);
+   free_irq(pci_irq_vector(dev->pdev, 0), dev);
 }
 
 static void ddb_remove(struct pci_dev *pdev)
@@ -105,7 +105,8 @@ static void ddb_irq_msi(struct ddb *dev, int nr)
int stat;
 
if (msi && pci_msi_enabled()) {
-   stat = pci_alloc_irq_vectors(dev->pdev, 1, nr, PCI_IRQ_MSI);
+   stat = pci_alloc_irq_vectors(dev->pdev, 1, nr,
+PCI_IRQ_MSI | PCI_IRQ_MSIX);
if (stat >= 1) {
dev->msi = stat;
dev_info(dev->dev, "using %d MSI interrupt(s)\n",
@@ -137,21 +138,24 @@ static int ddb_irq_init(struct ddb *dev)
if (dev->msi)
irq_flag = 0;
if (dev->msi == 2) {
-   stat = request_irq(dev->pdev->irq, ddb_irq_handler0,
-  irq_flag, "ddbridge", (void *)dev);
+   stat = request_irq(pci_irq_vector(dev->pdev, 0),
+  ddb_irq_handler0, irq_flag, "ddbridge",
+  (void *)dev);
if (stat < 0)
return stat;
-   stat = request_irq(dev->pdev->irq + 1, ddb_irq_handler1,
-  irq_flag, "ddbridge", (void *)dev);
+   stat = request_irq(pci_irq_vector(dev->pdev, 1),
+  ddb_irq_handler1, irq_flag, "ddbridge",
+  (void *)dev);
if (stat < 0) {
-   free_irq(dev->pdev->irq, dev);
+   free_irq(pci_irq_vector(dev->pdev, 0), dev);
return stat;
}
} else
 #endif
{
-   stat = request_irq(dev->pdev->irq, ddb_irq_handler,
-  irq_flag, "ddbridge", (void *)dev);
+   stat = request_irq(pci_irq_vector(dev->pdev, 0),
+  ddb_irq_handler, irq_flag, "ddbridge",
+  (void *)dev);
if (stat < 0)
return stat;
}
-- 
2.16.1



[PATCH 18/20] [media] ddbridge: add hardware defs and PCI IDs for MCI cards

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

Add PCI IDs and ddb_info for the new MCI-based MaxSX8 cards. Also add
needed defines so the cards can be hooked up into ddbridge's probe and
attach handling.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-hw.c   | 11 +++
 drivers/media/pci/ddbridge/ddbridge-main.c |  1 +
 drivers/media/pci/ddbridge/ddbridge.h  | 11 +++
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-hw.c 
b/drivers/media/pci/ddbridge/ddbridge-hw.c
index c6d14925e2fc..1d3ee6accdd5 100644
--- a/drivers/media/pci/ddbridge/ddbridge-hw.c
+++ b/drivers/media/pci/ddbridge/ddbridge-hw.c
@@ -311,6 +311,16 @@ static const struct ddb_info ddb_s2_48 = {
.tempmon_irq = 24,
 };
 
+static const struct ddb_info ddb_s2x_48 = {
+   .type = DDB_OCTOPUS_MCI,
+   .name = "Digital Devices MAX SX8",
+   .regmap   = &octopus_map,
+   .port_num = 4,
+   .i2c_mask = 0x00,
+   .tempmon_irq = 24,
+   .mci  = 4
+};
+
 //
 //
 //
@@ -346,6 +356,7 @@ static const struct ddb_device_id ddb_device_ids[] = {
DDB_DEVID(0x0008, 0x0036, ddb_isdbt_8),
DDB_DEVID(0x0008, 0x0037, ddb_c2t2i_v0_8),
DDB_DEVID(0x0008, 0x0038, ddb_c2t2i_8),
+   DDB_DEVID(0x0009, 0x0025, ddb_s2x_48),
DDB_DEVID(0x0006, 0x0039, ddb_ctv7),
DDB_DEVID(0x0011, 0x0040, ddb_ci),
DDB_DEVID(0x0011, 0x0041, ddb_cis),
diff --git a/drivers/media/pci/ddbridge/ddbridge-main.c 
b/drivers/media/pci/ddbridge/ddbridge-main.c
index 6356b48b3874..f4748cfd904b 100644
--- a/drivers/media/pci/ddbridge/ddbridge-main.c
+++ b/drivers/media/pci/ddbridge/ddbridge-main.c
@@ -264,6 +264,7 @@ static const struct pci_device_id ddb_id_table[] = {
DDB_DEVICE_ANY(0x0006),
DDB_DEVICE_ANY(0x0007),
DDB_DEVICE_ANY(0x0008),
+   DDB_DEVICE_ANY(0x0009),
DDB_DEVICE_ANY(0x0011),
DDB_DEVICE_ANY(0x0012),
DDB_DEVICE_ANY(0x0013),
diff --git a/drivers/media/pci/ddbridge/ddbridge.h 
b/drivers/media/pci/ddbridge/ddbridge.h
index cb69021a3443..72fe33cb72b9 100644
--- a/drivers/media/pci/ddbridge/ddbridge.h
+++ b/drivers/media/pci/ddbridge/ddbridge.h
@@ -112,11 +112,12 @@ struct ddb_ids {
 
 struct ddb_info {
int   type;
-#define DDB_NONE 0
-#define DDB_OCTOPUS  1
-#define DDB_OCTOPUS_CI   2
-#define DDB_OCTOPUS_MAX  5
+#define DDB_NONE0
+#define DDB_OCTOPUS 1
+#define DDB_OCTOPUS_CI  2
+#define DDB_OCTOPUS_MAX 5
 #define DDB_OCTOPUS_MAX_CT  6
+#define DDB_OCTOPUS_MCI 9
char *name;
u32   i2c_mask;
u8port_num;
@@ -133,6 +134,7 @@ struct ddb_info {
 #define TS_QUIRK_REVERSED 2
 #define TS_QUIRK_ALT_OSC  8
u32   tempmon_irq;
+   u8mci;
const struct ddb_regmap *regmap;
 };
 
@@ -253,6 +255,7 @@ struct ddb_port {
 #define DDB_CI_EXTERNAL_XO2_B13
 #define DDB_TUNER_DVBS_STV0910_PR 14
 #define DDB_TUNER_DVBC2T2I_SONY_P 15
+#define DDB_TUNER_MCI16
 
 #define DDB_TUNER_XO232
 #define DDB_TUNER_DVBS_STV0910   (DDB_TUNER_XO2 + 0)
-- 
2.16.1



[PATCH 13/20] [media] ddbridge: set devid entry for link 0

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

Currently, /sys/class/ddbridgeX/devid always reports 0 due to devid not
being set at all. Set the devid field alongside while storing all other
hardware ID data.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/pci/ddbridge/ddbridge-main.c 
b/drivers/media/pci/ddbridge/ddbridge-main.c
index 008be9066814..6356b48b3874 100644
--- a/drivers/media/pci/ddbridge/ddbridge-main.c
+++ b/drivers/media/pci/ddbridge/ddbridge-main.c
@@ -198,6 +198,7 @@ static int ddb_probe(struct pci_dev *pdev,
dev->link[0].ids.device = id->device;
dev->link[0].ids.subvendor = id->subvendor;
dev->link[0].ids.subdevice = pdev->subsystem_device;
+   dev->link[0].ids.devid = (id->device << 16) | id->vendor;
 
dev->link[0].dev = dev;
dev->link[0].info = get_ddb_info(id->vendor, id->device,
-- 
2.16.1



[PATCH 01/20] [media] dvb-frontends/stv0910: add init values for TSINSDELM/L

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

The TSINSDEL registers were lacking initialisation in the stv0910 demod
driver. Initialise them (both demods) in the probe() function.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/dvb-frontends/stv0910.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/dvb-frontends/stv0910.c 
b/drivers/media/dvb-frontends/stv0910.c
index 52355c14fd64..f5b5ce971c0c 100644
--- a/drivers/media/dvb-frontends/stv0910.c
+++ b/drivers/media/dvb-frontends/stv0910.c
@@ -1220,6 +1220,12 @@ static int probe(struct stv *state)
write_reg(state, RSTV0910_P1_I2CRPT, state->i2crpt);
write_reg(state, RSTV0910_P2_I2CRPT, state->i2crpt);
 
+   write_reg(state, RSTV0910_P1_TSINSDELM, 0x17);
+   write_reg(state, RSTV0910_P1_TSINSDELL, 0xff);
+
+   write_reg(state, RSTV0910_P2_TSINSDELM, 0x17);
+   write_reg(state, RSTV0910_P2_TSINSDELL, 0xff);
+
init_diseqc(state);
return 0;
 }
-- 
2.16.1



[PATCH 17/20] [media] ddbridge/max: implement MCI/MaxSX8 attach function

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

Implement frontend attachment as ddb_fe_attach_mci() into the
ddbridge-max module. The MaxSX8 MCI cards are part of the Max card series
and make use of the LNB controller driven by the already existing lnb
functionality, so here's where this code belongs to.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-max.c | 42 +++
 drivers/media/pci/ddbridge/ddbridge-max.h |  1 +
 2 files changed, 43 insertions(+)

diff --git a/drivers/media/pci/ddbridge/ddbridge-max.c 
b/drivers/media/pci/ddbridge/ddbridge-max.c
index dc6b81488746..739e4b444cf4 100644
--- a/drivers/media/pci/ddbridge/ddbridge-max.c
+++ b/drivers/media/pci/ddbridge/ddbridge-max.c
@@ -33,6 +33,7 @@
 #include "ddbridge.h"
 #include "ddbridge-regs.h"
 #include "ddbridge-io.h"
+#include "ddbridge-mci.h"
 
 #include "ddbridge-max.h"
 #include "mxl5xx.h"
@@ -452,3 +453,44 @@ int ddb_fe_attach_mxl5xx(struct ddb_input *input)
dvb->input = tuner;
return 0;
 }
+
+/**/
+/* MAX MCI related functions */
+
+int ddb_fe_attach_mci(struct ddb_input *input)
+{
+   struct ddb *dev = input->port->dev;
+   struct ddb_dvb *dvb = &input->port->dvb[input->nr & 1];
+   struct ddb_port *port = input->port;
+   struct ddb_link *link = &dev->link[port->lnr];
+   int demod, tuner;
+
+   demod = input->nr;
+   tuner = demod & 3;
+   if (fmode == 3)
+   tuner = 0;
+   dvb->fe = ddb_mci_attach(input, 0, demod, &dvb->set_input);
+   if (!dvb->fe) {
+   dev_err(dev->dev, "No MAXSX8 found!\n");
+   return -ENODEV;
+   }
+   if (!dvb->set_input) {
+   dev_err(dev->dev, "No MCI set_input function pointer!\n");
+   return -ENODEV;
+   }
+   if (input->nr < 4) {
+   lnb_command(dev, port->lnr, input->nr, LNB_CMD_INIT);
+   lnb_set_voltage(dev, port->lnr, input->nr, SEC_VOLTAGE_OFF);
+   }
+   ddb_lnb_init_fmode(dev, link, fmode);
+
+   dvb->fe->ops.set_voltage = max_set_voltage;
+   dvb->fe->ops.enable_high_lnb_voltage = max_enable_high_lnb_voltage;
+   dvb->fe->ops.set_tone = max_set_tone;
+   dvb->diseqc_send_master_cmd = dvb->fe->ops.diseqc_send_master_cmd;
+   dvb->fe->ops.diseqc_send_master_cmd = max_send_master_cmd;
+   dvb->fe->ops.diseqc_send_burst = max_send_burst;
+   dvb->fe->sec_priv = input;
+   dvb->input = tuner;
+   return 0;
+}
diff --git a/drivers/media/pci/ddbridge/ddbridge-max.h 
b/drivers/media/pci/ddbridge/ddbridge-max.h
index bf8bf38739f6..82efc53baa94 100644
--- a/drivers/media/pci/ddbridge/ddbridge-max.h
+++ b/drivers/media/pci/ddbridge/ddbridge-max.h
@@ -25,5 +25,6 @@
 
 int ddb_lnb_init_fmode(struct ddb *dev, struct ddb_link *link, u32 fm);
 int ddb_fe_attach_mxl5xx(struct ddb_input *input);
+int ddb_fe_attach_mci(struct ddb_input *input);
 
 #endif /* _DDBRIDGE_MAX_H */
-- 
2.16.1



[PATCH 05/20] [media] ddbridge: move ddb_wq and the wq+class initialisation to -core

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

Move the ddbridge module initialisation and cleanup code to ddbridge-core
and set up the ddb_wq workqueue there, and create and destroy the ddb
device class there aswell. Due to this, the prototypes for ddb_wq,
ddb_class_create() and ddb_class_destroy() aren't required in ddbridge.h
anymore, so remove them. Also, declare ddb_wq and the ddb_class_*()
functions static.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 32 +++---
 drivers/media/pci/ddbridge/ddbridge-main.c | 21 +++-
 drivers/media/pci/ddbridge/ddbridge.h  |  7 ++-
 3 files changed, 38 insertions(+), 22 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 933046d03db5..fb9a2cb758e6 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -100,7 +100,7 @@ MODULE_PARM_DESC(stv0910_single, "use stv0910 cards as 
single demods");
 
 static DEFINE_MUTEX(redirect_lock);
 
-struct workqueue_struct *ddb_wq;
+static struct workqueue_struct *ddb_wq;
 
 static struct ddb *ddbs[DDB_MAX_ADAPTER];
 
@@ -3055,7 +3055,7 @@ static struct class ddb_class = {
.devnode= ddb_devnode,
 };
 
-int ddb_class_create(void)
+static int ddb_class_create(void)
 {
ddb_major = register_chrdev(0, DDB_NAME, &ddb_fops);
if (ddb_major < 0)
@@ -3065,7 +3065,7 @@ int ddb_class_create(void)
return 0;
 }
 
-void ddb_class_destroy(void)
+static void ddb_class_destroy(void)
 {
class_unregister(&ddb_class);
unregister_chrdev(ddb_major, DDB_NAME);
@@ -3337,3 +3337,29 @@ void ddb_unmap(struct ddb *dev)
iounmap(dev->regs);
vfree(dev);
 }
+
+int ddb_exit_ddbridge(int stage, int error)
+{
+   switch (stage) {
+   default:
+   case 2:
+   destroy_workqueue(ddb_wq);
+   /* fall-through */
+   case 1:
+   ddb_class_destroy();
+   break;
+   }
+
+   return error;
+}
+
+int ddb_init_ddbridge(void)
+{
+   if (ddb_class_create() < 0)
+   return -1;
+   ddb_wq = alloc_workqueue("ddbridge", 0, 0);
+   if (!ddb_wq)
+   return ddb_exit_ddbridge(1, -1);
+
+   return 0;
+}
diff --git a/drivers/media/pci/ddbridge/ddbridge-main.c 
b/drivers/media/pci/ddbridge/ddbridge-main.c
index bde04dc39080..7088162af9d3 100644
--- a/drivers/media/pci/ddbridge/ddbridge-main.c
+++ b/drivers/media/pci/ddbridge/ddbridge-main.c
@@ -282,32 +282,25 @@ static struct pci_driver ddb_pci_driver = {
 
 static __init int module_init_ddbridge(void)
 {
-   int stat = -1;
+   int stat;
 
pr_info("Digital Devices PCIE bridge driver "
DDBRIDGE_VERSION
", Copyright (C) 2010-17 Digital Devices GmbH\n");
-   if (ddb_class_create() < 0)
-   return -1;
-   ddb_wq = create_workqueue("ddbridge");
-   if (!ddb_wq)
-   goto exit1;
+   stat = ddb_init_ddbridge();
+   if (stat < 0)
+   return stat;
stat = pci_register_driver(&ddb_pci_driver);
if (stat < 0)
-   goto exit2;
-   return stat;
-exit2:
-   destroy_workqueue(ddb_wq);
-exit1:
-   ddb_class_destroy();
+   ddb_exit_ddbridge(0, stat);
+
return stat;
 }
 
 static __exit void module_exit_ddbridge(void)
 {
pci_unregister_driver(&ddb_pci_driver);
-   destroy_workqueue(ddb_wq);
-   ddb_class_destroy();
+   ddb_exit_ddbridge(0, 0);
 }
 
 module_init(module_init_ddbridge);
diff --git a/drivers/media/pci/ddbridge/ddbridge.h 
b/drivers/media/pci/ddbridge/ddbridge.h
index e22e67d7e0fe..dbd5f551ce76 100644
--- a/drivers/media/pci/ddbridge/ddbridge.h
+++ b/drivers/media/pci/ddbridge/ddbridge.h
@@ -368,9 +368,6 @@ int ddbridge_flashread(struct ddb *dev, u32 link, u8 *buf, 
u32 addr, u32 len);
 
 //
 
-/* ddbridge-main.c (modparams) */
-extern struct workqueue_struct *ddb_wq;
-
 /* ddbridge-core.c */
 void ddb_ports_detach(struct ddb *dev);
 void ddb_ports_release(struct ddb *dev);
@@ -383,9 +380,9 @@ void ddb_ports_init(struct ddb *dev);
 int ddb_buffers_alloc(struct ddb *dev);
 int ddb_ports_attach(struct ddb *dev);
 int ddb_device_create(struct ddb *dev);
-int ddb_class_create(void);
-void ddb_class_destroy(void);
 int ddb_init(struct ddb *dev);
 void ddb_unmap(struct ddb *dev);
+int ddb_exit_ddbridge(int stage, int error);
+int ddb_init_ddbridge(void);
 
 #endif /* DDBRIDGE_H */
-- 
2.16.1



[PATCH 00/20] dddvb/ddbridge-0.9.33

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

This series brings all relevant changes from the upstream dddvb-0.9.33
driver package to the in-kernel ddbridge and stv0910, though a few changes
were picked up and merged previously already.

Summary of changes:
* stv0910: initialisation fixes and fixed CNR reporting (uvalue vs.
  svalue)
* ddbridge: general code move, cleanups and fixups
* ddbridge: fixes and improvements to the IRQ setup and handling, and
  MSI-X support
* ddbridge: configurable DMA buffers (via modparam)
* ddbridge: dummy tuner option, useful for debugging and stress testing
  purposes
* ddbridge: support for the new MCI card types, and namely the new MaxSX8
  cards

Patches were build-tested in their order and are bisect safe. Besides the
modparam move, everything is picked up from dddvb-0.9.33.

The series adds the new ddbridge-mci.[c|h] files. Here, SPDX headers were
already put in place, but until things have been fully sorted out, the
original GPL boiler plate is kept in place for now.

Please pick up and merge.

Daniel Scheller (20):
  [media] dvb-frontends/stv0910: add init values for TSINSDELM/L
  [media] dvb-frontends/stv0910: increase parallel TS output speed
  [media] dvb-frontends/stv0910: fix CNR reporting in read_snr()
  [media] ddbridge: move modparams to ddbridge-core.c
  [media] ddbridge: move ddb_wq and the wq+class initialisation to -core
  [media] ddbridge: move MSI IRQ cleanup to a helper function
  [media] ddbridge: request/free_irq using pci_irq_vector, enable MSI-X
  [media] ddbridge: add helper for IRQ handler setup
  [media] ddbridge: add macros to handle IRQs in nibble and byte blocks
  [media] ddbridge: improve separated MSI IRQ handling
  [media] ddbridge: use spin_lock_irqsave() in output_work()
  [media] ddbridge: fix output buffer check
  [media] ddbridge: set devid entry for link 0
  [media] ddbridge: make DMA buffer count and size modparam-configurable
  [media] ddbridge: support dummy tuners with 125MByte/s dummy data
stream
  [media] ddbridge: initial support for MCI-based MaxSX8 cards
  [media] ddbridge/max: implement MCI/MaxSX8 attach function
  [media] ddbridge: add hardware defs and PCI IDs for MCI cards
  [media] ddbridge: recognize and attach the MaxSX8 cards
  [media] ddbridge: set driver version to 0.9.33-integrated

 drivers/media/dvb-frontends/stv0910.c  |  12 +-
 drivers/media/pci/ddbridge/Kconfig |   1 +
 drivers/media/pci/ddbridge/Makefile|   2 +-
 drivers/media/pci/ddbridge/ddbridge-core.c | 299 +++-
 drivers/media/pci/ddbridge/ddbridge-hw.c   |  11 +
 drivers/media/pci/ddbridge/ddbridge-i2c.c  |   5 +-
 drivers/media/pci/ddbridge/ddbridge-main.c |  91 ++---
 drivers/media/pci/ddbridge/ddbridge-max.c  |  42 +++
 drivers/media/pci/ddbridge/ddbridge-max.h  |   1 +
 drivers/media/pci/ddbridge/ddbridge-mci.c  | 550 +
 drivers/media/pci/ddbridge/ddbridge-mci.h  | 152 
 drivers/media/pci/ddbridge/ddbridge.h  |  50 +--
 12 files changed, 1030 insertions(+), 186 deletions(-)
 create mode 100644 drivers/media/pci/ddbridge/ddbridge-mci.c
 create mode 100644 drivers/media/pci/ddbridge/ddbridge-mci.h

-- 
2.16.1



[PATCH 14/20] [media] ddbridge: make DMA buffer count and size modparam-configurable

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

Make the number of DMA buffers and their size configurable using module
parameters. Being able to set these to a higher number might help on
busy systems when handling overall high data rates without having to
edit the driver sources and recompile things.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 30 --
 drivers/media/pci/ddbridge/ddbridge.h  | 12 
 2 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index e9c2e3e5d64b..8907551b02e4 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -96,6 +96,15 @@ static int stv0910_single;
 module_param(stv0910_single, int, 0444);
 MODULE_PARM_DESC(stv0910_single, "use stv0910 cards as single demods");
 
+static int dma_buf_num = 8;
+module_param(dma_buf_num, int, 0444);
+MODULE_PARM_DESC(dma_buf_num, "Number of DMA buffers, possible values: 8-32");
+
+static int dma_buf_size = 21;
+module_param(dma_buf_size, int, 0444);
+MODULE_PARM_DESC(dma_buf_size,
+"DMA buffer size as multiple of 128*47, possible values: 
1-43");
+
 //
 
 static DEFINE_MUTEX(redirect_lock);
@@ -2187,16 +2196,16 @@ static void ddb_dma_init(struct ddb_io *io, int nr, int 
out)
INIT_WORK(&dma->work, output_work);
dma->regs = rm->odma->base + rm->odma->size * nr;
dma->bufregs = rm->odma_buf->base + rm->odma_buf->size * nr;
-   dma->num = OUTPUT_DMA_BUFS;
-   dma->size = OUTPUT_DMA_SIZE;
-   dma->div = OUTPUT_DMA_IRQ_DIV;
+   dma->num = dma_buf_num;
+   dma->size = dma_buf_size * 128 * 47;
+   dma->div = 1;
} else {
INIT_WORK(&dma->work, input_work);
dma->regs = rm->idma->base + rm->idma->size * nr;
dma->bufregs = rm->idma_buf->base + rm->idma_buf->size * nr;
-   dma->num = INPUT_DMA_BUFS;
-   dma->size = INPUT_DMA_SIZE;
-   dma->div = INPUT_DMA_IRQ_DIV;
+   dma->num = dma_buf_num;
+   dma->size = dma_buf_size * 128 * 47;
+   dma->div = 1;
}
ddbwritel(io->port->dev, 0, DMA_BUFFER_ACK(dma));
dev_dbg(io->port->dev->dev, "init link %u, io %u, dma %u, dmaregs %08x 
bufregs %08x\n",
@@ -3353,6 +3362,15 @@ int ddb_exit_ddbridge(int stage, int error)
 
 int ddb_init_ddbridge(void)
 {
+   if (dma_buf_num < 8)
+   dma_buf_num = 8;
+   if (dma_buf_num > 32)
+   dma_buf_num = 32;
+   if (dma_buf_size < 1)
+   dma_buf_size = 1;
+   if (dma_buf_size > 43)
+   dma_buf_size = 43;
+
if (ddb_class_create() < 0)
return -1;
ddb_wq = alloc_workqueue("ddbridge", 0, 0);
diff --git a/drivers/media/pci/ddbridge/ddbridge.h 
b/drivers/media/pci/ddbridge/ddbridge.h
index de9ddf1068bf..86db6f19369a 100644
--- a/drivers/media/pci/ddbridge/ddbridge.h
+++ b/drivers/media/pci/ddbridge/ddbridge.h
@@ -136,20 +136,8 @@ struct ddb_info {
const struct ddb_regmap *regmap;
 };
 
-/* DMA_SIZE MUST be smaller than 256k and
- * MUST be divisible by 188 and 128 !!!
- */
-
 #define DMA_MAX_BUFS 32  /* hardware table limit */
 
-#define INPUT_DMA_BUFS 8
-#define INPUT_DMA_SIZE (128 * 47 * 21)
-#define INPUT_DMA_IRQ_DIV 1
-
-#define OUTPUT_DMA_BUFS 8
-#define OUTPUT_DMA_SIZE (128 * 47 * 21)
-#define OUTPUT_DMA_IRQ_DIV 1
-
 struct ddb;
 struct ddb_port;
 
-- 
2.16.1



[PATCH 08/20] [media] ddbridge: add helper for IRQ handler setup

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

Introduce the ddb_irq_set() helper function (along with a matching
prototype in ddbridge.h) to improve the set up of the IRQ handlers
and handler_data, and rework storing this data into the ddb_link
using a new ddb_irq struct. This also does the necessary rework
of affected variables. And while at it, always do queue_work in
input_handler() as there's not much of a difference to directly
calling input_work if there's no ptr at input->redi, or queueing
this call.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 53 +-
 drivers/media/pci/ddbridge/ddbridge-i2c.c  |  5 ++-
 drivers/media/pci/ddbridge/ddbridge.h  | 11 +--
 3 files changed, 41 insertions(+), 28 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index fb9a2cb758e6..be6935bd0cb5 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -108,6 +108,16 @@ static struct ddb *ddbs[DDB_MAX_ADAPTER];
 //
 //
 
+struct ddb_irq *ddb_irq_set(struct ddb *dev, u32 link, u32 nr,
+   void (*handler)(void *), void *data)
+{
+   struct ddb_irq *irq = &dev->link[link].irq[nr];
+
+   irq->handler = handler;
+   irq->data = data;
+   return irq;
+}
+
 static void ddb_set_dma_table(struct ddb_io *io)
 {
struct ddb *dev = io->port->dev;
@@ -2109,26 +2119,18 @@ static void input_work(struct work_struct *work)
spin_unlock_irqrestore(&dma->lock, flags);
 }
 
-static void input_handler(unsigned long data)
+static void input_handler(void *data)
 {
struct ddb_input *input = (struct ddb_input *)data;
struct ddb_dma *dma = input->dma;
 
-   /*
-* If there is no input connected, input_tasklet() will
-* just copy pointers and ACK. So, there is no need to go
-* through the tasklet scheduler.
-*/
-   if (input->redi)
-   queue_work(ddb_wq, &dma->work);
-   else
-   input_work(&dma->work);
+   queue_work(ddb_wq, &dma->work);
 }
 
-static void output_handler(unsigned long data)
+static void output_work(struct work_struct *work)
 {
-   struct ddb_output *output = (struct ddb_output *)data;
-   struct ddb_dma *dma = output->dma;
+   struct ddb_dma *dma = container_of(work, struct ddb_dma, work);
+   struct ddb_output *output = (struct ddb_output *)dma->io;
struct ddb *dev = output->port->dev;
 
spin_lock(&dma->lock);
@@ -2144,6 +2146,14 @@ static void output_handler(unsigned long data)
spin_unlock(&dma->lock);
 }
 
+static void output_handler(void *data)
+{
+   struct ddb_output *output = (struct ddb_output *)data;
+   struct ddb_dma *dma = output->dma;
+
+   queue_work(ddb_wq, &dma->work);
+}
+
 //
 //
 
@@ -2174,6 +2184,7 @@ static void ddb_dma_init(struct ddb_io *io, int nr, int 
out)
spin_lock_init(&dma->lock);
init_waitqueue_head(&dma->wq);
if (out) {
+   INIT_WORK(&dma->work, output_work);
dma->regs = rm->odma->base + rm->odma->size * nr;
dma->bufregs = rm->odma_buf->base + rm->odma_buf->size * nr;
dma->num = OUTPUT_DMA_BUFS;
@@ -2218,8 +2229,7 @@ static void ddb_input_init(struct ddb_port *port, int nr, 
int pnr, int anr)
dev_dbg(dev->dev, "init link %u, input %u, handler %u\n",
port->lnr, nr, dma_nr + base);
 
-   dev->handler[0][dma_nr + base] = input_handler;
-   dev->handler_data[0][dma_nr + base] = (unsigned long)input;
+   ddb_irq_set(dev, 0, dma_nr + base, &input_handler, input);
ddb_dma_init(input, dma_nr, 0);
}
 }
@@ -2244,8 +2254,7 @@ static void ddb_output_init(struct ddb_port *port, int nr)
const struct ddb_regmap *rm0 = io_regmap(output, 0);
u32 base = rm0->irq_base_odma;
 
-   dev->handler[0][nr + base] = output_handler;
-   dev->handler_data[0][nr + base] = (unsigned long)output;
+   ddb_irq_set(dev, 0, nr + base, &output_handler, output);
ddb_dma_init(output, nr, 1);
}
 }
@@ -2389,8 +2398,9 @@ void ddb_ports_release(struct ddb *dev)
 //
 
 #define IRQ_HANDL

[PATCH 11/20] [media] ddbridge: use spin_lock_irqsave() in output_work()

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

Make sure to save IRQ states before taking the dma lock, as already done
in it's input_work() counterpart.

Picked up from the upstream dddvb-0.9.33 release.

Signed-off-by: Daniel Scheller 
---
 drivers/media/pci/ddbridge/ddbridge-core.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c 
b/drivers/media/pci/ddbridge/ddbridge-core.c
index 9d91221dacc4..c22537eceee5 100644
--- a/drivers/media/pci/ddbridge/ddbridge-core.c
+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
@@ -2132,18 +2132,18 @@ static void output_work(struct work_struct *work)
struct ddb_dma *dma = container_of(work, struct ddb_dma, work);
struct ddb_output *output = (struct ddb_output *)dma->io;
struct ddb *dev = output->port->dev;
+   unsigned long flags;
 
-   spin_lock(&dma->lock);
-   if (!dma->running) {
-   spin_unlock(&dma->lock);
-   return;
-   }
+   spin_lock_irqsave(&dma->lock, flags);
+   if (!dma->running)
+   goto unlock_exit;
dma->stat = ddbreadl(dev, DMA_BUFFER_CURRENT(dma));
dma->ctrl = ddbreadl(dev, DMA_BUFFER_CONTROL(dma));
if (output->redi)
output_ack_input(output, output->redi);
wake_up(&dma->wq);
-   spin_unlock(&dma->lock);
+unlock_exit:
+   spin_unlock_irqrestore(&dma->lock, flags);
 }
 
 static void output_handler(void *data)
-- 
2.16.1



Re: [PATCH 00/20] dddvb/ddbridge-0.9.33

2018-04-05 Thread Daniel Scheller
Am Mon,  2 Apr 2018 20:24:07 +0200
schrieb Daniel Scheller :

> From: Daniel Scheller 
> 
> This series brings all relevant changes from the upstream dddvb-0.9.33
> driver package to the in-kernel ddbridge and stv0910, though a few
> changes were picked up and merged previously already.
> 
> Summary of changes:
> * stv0910: initialisation fixes and fixed CNR reporting (uvalue vs.
>   svalue)
> * ddbridge: general code move, cleanups and fixups
> * ddbridge: fixes and improvements to the IRQ setup and handling, and
>   MSI-X support
> * ddbridge: configurable DMA buffers (via modparam)
> * ddbridge: dummy tuner option, useful for debugging and stress
> testing purposes
> * ddbridge: support for the new MCI card types, and namely the new
> MaxSX8 cards
> 
> Patches were build-tested in their order and are bisect safe. Besides
> the modparam move, everything is picked up from dddvb-0.9.33.
> 
> The series adds the new ddbridge-mci.[c|h] files. Here, SPDX headers
> were already put in place, but until things have been fully sorted
> out, the original GPL boiler plate is kept in place for now.
> 
> Please pick up and merge.
> 
> Daniel Scheller (20):
>   [media] dvb-frontends/stv0910: add init values for TSINSDELM/L
>   [media] dvb-frontends/stv0910: increase parallel TS output speed
>   [media] dvb-frontends/stv0910: fix CNR reporting in read_snr()
>   [media] ddbridge: move modparams to ddbridge-core.c
>   [media] ddbridge: move ddb_wq and the wq+class initialisation to
> -core [media] ddbridge: move MSI IRQ cleanup to a helper function
>   [media] ddbridge: request/free_irq using pci_irq_vector, enable
> MSI-X [media] ddbridge: add helper for IRQ handler setup
>   [media] ddbridge: add macros to handle IRQs in nibble and byte
> blocks [media] ddbridge: improve separated MSI IRQ handling
>   [media] ddbridge: use spin_lock_irqsave() in output_work()
>   [media] ddbridge: fix output buffer check
>   [media] ddbridge: set devid entry for link 0
>   [media] ddbridge: make DMA buffer count and size
> modparam-configurable [media] ddbridge: support dummy tuners with
> 125MByte/s dummy data stream
>   [media] ddbridge: initial support for MCI-based MaxSX8 cards
>   [media] ddbridge/max: implement MCI/MaxSX8 attach function
>   [media] ddbridge: add hardware defs and PCI IDs for MCI cards
>   [media] ddbridge: recognize and attach the MaxSX8 cards
>   [media] ddbridge: set driver version to 0.9.33-integrated
> 
>  drivers/media/dvb-frontends/stv0910.c  |  12 +-
>  drivers/media/pci/ddbridge/Kconfig |   1 +
>  drivers/media/pci/ddbridge/Makefile|   2 +-
>  drivers/media/pci/ddbridge/ddbridge-core.c | 299 +++-
>  drivers/media/pci/ddbridge/ddbridge-hw.c   |  11 +
>  drivers/media/pci/ddbridge/ddbridge-i2c.c  |   5 +-
>  drivers/media/pci/ddbridge/ddbridge-main.c |  91 ++---
>  drivers/media/pci/ddbridge/ddbridge-max.c  |  42 +++
>  drivers/media/pci/ddbridge/ddbridge-max.h  |   1 +
>  drivers/media/pci/ddbridge/ddbridge-mci.c  | 550
> +
> drivers/media/pci/ddbridge/ddbridge-mci.h  | 152 
> drivers/media/pci/ddbridge/ddbridge.h  |  50 +-- 12 files
> changed, 1030 insertions(+), 186 deletions(-) create mode 100644
> drivers/media/pci/ddbridge/ddbridge-mci.c create mode 100644
> drivers/media/pci/ddbridge/ddbridge-mci.h
> 

Please refrain from merging this as it is now. Recently, one issue has
been discovered with one of the stv0910 patches which renders at least
the CineS2 V7A cards (specifically the tuners soldered on them,
extensions will still work fine) unusable. Upstream has this issue
aswell. This is currently under investigation.

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


  1   2   3   4   5   6   >