Re: [PATCH v2 2/3] media: dvb: represent min/max/step/tolerance freqs in Hz

2018-07-06 Thread Matthias Schwarzott
Am 06.07.2018 um 00:59 schrieb Mauro Carvalho Chehab:

Hi Mauro,

I have one comment below.

> Right now, satellite frontend drivers specify frequencies in kHz,
> while terrestrial/cable ones specify in Hz. That's confusing
> for developers.
> 
> However, the main problem is that universal frontends capable
> of handling both satellite and non-satelite delivery systems
> are appearing. We end by needing to hack the drivers in
> order to support such hybrid frontends.
> 
> So, convert everything to specify frontend frequencies in Hz.
> 
> Tested-by: Katsuhiro Suzuki 
> Signed-off-by: Mauro Carvalho Chehab 
> ---

> diff --git a/drivers/media/dvb-core/dvb_frontend.c 
> b/drivers/media/dvb-core/dvb_frontend.c
> index 75e95b56f8b3..3b9dca7d7d02 100644
> --- a/drivers/media/dvb-core/dvb_frontend.c
> +++ b/drivers/media/dvb-core/dvb_frontend.c
[...]
> @@ -2391,9 +2417,19 @@ static int dvb_frontend_handle_ioctl(struct file *file,
>  
>   case FE_GET_INFO: {
>   struct dvb_frontend_info *info = parg;
> + memset(info, 0, sizeof(*info));
>  
> - memcpy(info, >ops.info, sizeof(struct dvb_frontend_info));
> - dvb_frontend_get_frequency_limits(fe, >frequency_min, 
> >frequency_max);
> + strcpy(info->name, fe->ops.info.name);
> + info->frequency_stepsize = fe->ops.info.frequency_stepsize_hz;
> + info->frequency_tolerance = fe->ops.info.frequency_tolerance_hz;

The variables frequency_stepsize and frequency_tolerance are assigned
again some lines below.

> + info->symbol_rate_min = fe->ops.info.symbol_rate_min;
> + info->symbol_rate_max = fe->ops.info.symbol_rate_max;
> + info->symbol_rate_tolerance = 
> fe->ops.info.symbol_rate_tolerance;
> + info->caps = fe->ops.info.caps;
> + info->frequency_stepsize = dvb_frontend_get_stepsize(fe);
> + dvb_frontend_get_frequency_limits(fe, >frequency_min,
> +   >frequency_max,
> +   >frequency_tolerance);
>  
>   /*
>* Associate the 4 delivery systems supported by DVBv3

Matthias


Re: [PATCH] cx231xx: Increase USB bridge bandwidth

2018-06-05 Thread Matthias Schwarzott
Am 02.04.2018 um 21:59 schrieb Brad Love:
> The cx231xx USB bridge has issue streaming QAM256 DVB-C channels.
> QAM64 channels were fine, but QAM256 channels produced corrupted
> transport streams.
> 
> cx231xx alt mode 4 does not provide enough bandwidth to acommodate
> QAM256 DVB-C channels, most likely DVB-T2 channels would break up
> as well. Alt mode 5 increases bridge bandwidth to 90Mbps, and
> fixes QAM256 DVB-C streaming.
> 
Hi Brad,

I read through the media commits applied in the last weeks.

This patch looks so simple and yet resolves the (for me) unexplainable
behaviour of the Hauppauge WinTV-HVR-930C-HD. DVB-C reception did only
produce garbage, but the the same demod driver (si2165) does work
perfectly in a PCI device.

Thank you for fixing this issue.

Regards
Matthias


Re: [PATCH 2/9] cx231xx: Use board profile values for addresses

2018-04-19 Thread Matthias Schwarzott
Am 17.04.2018 um 18:39 schrieb Brad Love:
> Replace all usage of hard coded values with
> the proper field from the board profile.
> 

Hi Brad,

will there be any interference with the usage to configure the analog
tuner via the fields tuner_addr and tuner_type?

Regards
Matthias

> Signed-off-by: Brad Love 
> ---
>  drivers/media/usb/cx231xx/cx231xx-dvb.c | 19 +--
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c 
> b/drivers/media/usb/cx231xx/cx231xx-dvb.c
> index 67ed667..99f1a77 100644
> --- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
> +++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
> @@ -728,7 +728,7 @@ static int dvb_init(struct cx231xx *dev)
>   dvb->frontend[0]->callback = cx231xx_tuner_callback;
>  
>   if (!dvb_attach(tda18271_attach, dev->dvb->frontend[0],
> -0x60, tuner_i2c,
> +dev->board.tuner_addr, tuner_i2c,
>  _rde253s_tunerconfig)) {
>   result = -EINVAL;
>   goto out_free;
> @@ -752,7 +752,7 @@ static int dvb_init(struct cx231xx *dev)
>   dvb->frontend[0]->callback = cx231xx_tuner_callback;
>  
>   if (!dvb_attach(tda18271_attach, dev->dvb->frontend[0],
> -0x60, tuner_i2c,
> +dev->board.tuner_addr, tuner_i2c,
>  _rde253s_tunerconfig)) {
>   result = -EINVAL;
>   goto out_free;
> @@ -779,7 +779,7 @@ static int dvb_init(struct cx231xx *dev)
>   dvb->frontend[0]->callback = cx231xx_tuner_callback;
>  
>   dvb_attach(tda18271_attach, dev->dvb->frontend[0],
> -0x60, tuner_i2c,
> +dev->board.tuner_addr, tuner_i2c,
>  _tda18271_config);
>   break;
>  
> @@ -797,7 +797,7 @@ static int dvb_init(struct cx231xx *dev)
>  
>   memset(, 0, sizeof(struct i2c_board_info));
>   strlcpy(info.type, "si2165", I2C_NAME_SIZE);
> - info.addr = 0x64;
> + info.addr = dev->board.demod_addr;
>   info.platform_data = _pdata;
>   request_module(info.type);
>   client = i2c_new_device(demod_i2c, );
> @@ -822,8 +822,7 @@ static int dvb_init(struct cx231xx *dev)
>   dvb->frontend[0]->callback = cx231xx_tuner_callback;
>  
>   dvb_attach(tda18271_attach, dev->dvb->frontend[0],
> - 0x60,
> - tuner_i2c,
> + dev->board.tuner_addr, tuner_i2c,
>   _tda18271_config);
>  
>   dev->cx231xx_reset_analog_tuner = NULL;
> @@ -844,7 +843,7 @@ static int dvb_init(struct cx231xx *dev)
>  
>   memset(, 0, sizeof(struct i2c_board_info));
>   strlcpy(info.type, "si2165", I2C_NAME_SIZE);
> - info.addr = 0x64;
> + info.addr = dev->board.demod_addr;
>   info.platform_data = _pdata;
>   request_module(info.type);
>   client = i2c_new_device(demod_i2c, );
> @@ -879,7 +878,7 @@ static int dvb_init(struct cx231xx *dev)
>   si2157_config.if_port = 1;
>   si2157_config.inversion = true;
>   strlcpy(info.type, "si2157", I2C_NAME_SIZE);
> - info.addr = 0x60;
> + info.addr = dev->board.tuner_addr;
>   info.platform_data = _config;
>   request_module("si2157");
>  
> @@ -938,7 +937,7 @@ static int dvb_init(struct cx231xx *dev)
>   si2157_config.if_port = 1;
>   si2157_config.inversion = true;
>   strlcpy(info.type, "si2157", I2C_NAME_SIZE);
> - info.addr = 0x60;
> + info.addr = dev->board.tuner_addr;
>   info.platform_data = _config;
>   request_module("si2157");
>  
> @@ -985,7 +984,7 @@ static int dvb_init(struct cx231xx *dev)
>   dvb->frontend[0]->callback = cx231xx_tuner_callback;
>  
>   dvb_attach(tda18271_attach, dev->dvb->frontend[0],
> -0x60, tuner_i2c,
> +dev->board.tuner_addr, tuner_i2c,
>  _tda18271_config);
>   break;
>  
> 



Re: [PATCH 5/9] cx231xx: Switch to using new dvb i2c helpers

2018-04-19 Thread Matthias Schwarzott
Am 17.04.2018 um 18:39 schrieb Brad Love:
> Mostly very straight forward replace of blocks with equivalent code.
> 
> Cleanup added at end of dvb_init in case of failure.
> 
Hi Brad,

I have some suggestions. See below.

Matthias

> Signed-off-by: Brad Love 
> ---
>  drivers/media/usb/cx231xx/cx231xx-dvb.c | 331 
> 
>  1 file changed, 82 insertions(+), 249 deletions(-)
> 
> diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c 
> b/drivers/media/usb/cx231xx/cx231xx-dvb.c
> index 681610f..318a6cd 100644
> --- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
> +++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
> @@ -613,23 +613,18 @@ static void unregister_dvb(struct cx231xx_dvb *dvb)
>   dvb_frontend_detach(dvb->frontend[1]);
>   dvb_frontend_detach(dvb->frontend[0]);
>   dvb_unregister_adapter(>adapter);
> +
>   /* remove I2C tuner */
>   client = dvb->i2c_client_tuner;
> - if (client) {
> - module_put(client->dev.driver->owner);
> - i2c_unregister_device(client);
> - }
> - /* remove I2C demod */
> + if (client)
> + dvb_module_release(client);
The pointer check is not needed, dvb_module_release does check itself
for NULL.

Other drivers added code to set the client-pointers to NULL after
releasing it.

I suggest to do it like this:
/* remove I2C tuner */
dvb_module_release(dvb->i2c_client_tuner);
dvb->i2c_client_tuner = NULL;


> + /* remove I2C demod(s) */
>   client = dvb->i2c_client_demod[1];
> - if (client) {
> - module_put(client->dev.driver->owner);
> - i2c_unregister_device(client);
> - }
> + if (client)
> + dvb_module_release(client);
>   client = dvb->i2c_client_demod[0];
> - if (client) {
> - module_put(client->dev.driver->owner);
> - i2c_unregister_device(client);
> - }
> + if (client)
> + dvb_module_release(client);

>  }
>  
>  static int dvb_init(struct cx231xx *dev)
> @@ -638,6 +633,8 @@ static int dvb_init(struct cx231xx *dev)
>   struct cx231xx_dvb *dvb;
>   struct i2c_adapter *tuner_i2c;
>   struct i2c_adapter *demod_i2c;
> + struct i2c_client *client;
> + struct i2c_adapter *adapter;
>  
>   if (!dev->board.has_dvb) {
>   /* This device does not support the extension */
> @@ -785,8 +782,6 @@ static int dvb_init(struct cx231xx *dev)
>  
>   case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx:
>   {
> - struct i2c_client *client;
> - struct i2c_board_info info;
>   struct si2165_platform_data si2165_pdata = {};
>  
>   /* attach demod */
> @@ -794,25 +789,14 @@ static int dvb_init(struct cx231xx *dev)
>   si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL;
>   si2165_pdata.ref_freq_hz = 1600;
>  
> - memset(, 0, sizeof(struct i2c_board_info));
> - strlcpy(info.type, "si2165", I2C_NAME_SIZE);
> - info.addr = dev->board.demod_addr;
> - info.platform_data = _pdata;
> - request_module(info.type);
> - client = i2c_new_device(demod_i2c, );
> - if (!client || !client->dev.driver || !dev->dvb->frontend[0]) {
> - dev_err(dev->dev,
> - "Failed to attach SI2165 front end\n");
> - result = -EINVAL;
> - goto out_free;
> - }
> -
> - if (!try_module_get(client->dev.driver->owner)) {
> - i2c_unregister_device(client);
> + /* perform tuner probe/init/attach */
> + client = dvb_module_probe("si2165", NULL, demod_i2c,
> + dev->board.demod_addr,
> + _pdata);
> + if (!client) {
>   result = -ENODEV;
>   goto out_free;
>   }
> -
>   dvb->i2c_client_demod[0] = client;
>  
>   dev->dvb->frontend[0]->ops.i2c_gate_ctrl = NULL;
> @@ -829,8 +813,6 @@ static int dvb_init(struct cx231xx *dev)
>   }
>   case CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx:
>   {
> - struct i2c_client *client;
> - struct i2c_board_info info;
>   struct si2165_platform_data si2165_pdata = {};
>   struct si2157_config si2157_config = {};
>  
> @@ -839,29 +821,16 @@ static int dvb_init(struct cx231xx *dev)
>   si2165_pdata.chip_mode = SI2165_MODE_PLL_EXT;
>   si2165_pdata.ref_freq_hz = 2400;
>  
> - memset(, 0, sizeof(struct i2c_board_info));
> - strlcpy(info.type, "si2165", I2C_NAME_SIZE);
> - info.addr = dev->board.demod_addr;
> - info.platform_data = _pdata;
> - request_module(info.type);
> - client = i2c_new_device(demod_i2c, );
> - if 

Re: [PATCH 1/3] media: si2165: Remove owner assignment from i2c_driver

2018-04-08 Thread Matthias Schwarzott
Thank you for sending this patch.

Am 24.03.2018 um 15:01 schrieb Fabio Estevam:
> From: Fabio Estevam <fabio.este...@nxp.com>
> 
> Structure i2c_driver does not need to set the owner field, as this will
> be populated by the driver core.
> 
> Generated by scripts/coccinelle/api/platform_no_drv_owner.cocci.
> 
> Cc: Matthias Schwarzott <z...@gentoo.org>
> Signed-off-by: Fabio Estevam <fabio.este...@nxp.com>
> ---
>  drivers/media/dvb-frontends/si2165.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/media/dvb-frontends/si2165.c 
> b/drivers/media/dvb-frontends/si2165.c
> index 2dd336f..d132e3c 100644
> --- a/drivers/media/dvb-frontends/si2165.c
> +++ b/drivers/media/dvb-frontends/si2165.c
> @@ -1299,7 +1299,6 @@ MODULE_DEVICE_TABLE(i2c, si2165_id_table);
>  
>  static struct i2c_driver si2165_driver = {
>   .driver = {
> - .owner  = THIS_MODULE,
>   .name   = "si2165",
>   },
>   .probe  = si2165_probe,
> 

The change is fine.

Reviewed-by: Matthias Schwarzott <z...@gentoo.org>


Re: [PATCH 01/16] omap: omap-iommu.h: allow building drivers with COMPILE_TEST

2018-04-08 Thread Matthias Schwarzott
Am 05.04.2018 um 19:54 schrieb Mauro Carvalho Chehab:
> Drivers that depend on omap-iommu.h (currently, just omap3isp)
> need a stub implementation in order to be built with COMPILE_TEST.
> 
> Signed-off-by: Mauro Carvalho Chehab 
> ---
>  include/linux/omap-iommu.h | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/include/linux/omap-iommu.h b/include/linux/omap-iommu.h
> index c1aede46718b..0c21fc5b002e 100644
> --- a/include/linux/omap-iommu.h
> +++ b/include/linux/omap-iommu.h
> @@ -13,7 +13,12 @@
>  #ifndef _OMAP_IOMMU_H_
>  #define _OMAP_IOMMU_H_
>  
> +#ifdef CONFIG_OMAP_IOMMU
>  extern void omap_iommu_save_ctx(struct device *dev);
>  extern void omap_iommu_restore_ctx(struct device *dev);
> +#else
> +static inline void omap_iommu_save_ctx(struct device *dev) {};
> +static inline void omap_iommu_restore_ctx(struct device *dev) {};

The semicolons at end of line are unnecessary.

> +#endif
>  
>  #endif
> 

Regards
Matthias


Re: [PATCH 7/9] lgdt3306a: Set fe ops.release to NULL if probed

2018-01-08 Thread Matthias Schwarzott
Am 05.01.2018 um 01:19 schrieb Michael Ira Krufky:
> On Thu, Jan 4, 2018 at 7:04 PM, Brad Love  wrote:
>> If release is part of frontend ops then it is called in the
>> course of dvb_frontend_detach. The process also decrements
>> the module usage count. The problem is if the lgdt3306a
>> driver is reached via i2c_new_device, then when it is
>> eventually destroyed remove is called, which further
>> decrements the module usage count to negative. After this
>> occurs the driver is in a bad state and no longer works.
>> Also fixed by NULLing out the release callback is a double
>> kfree of state, which introduces arbitrary oopses/GPF.
>> This problem is only currently reachable via the em28xx driver.
>>
>> On disconnect of Hauppauge SoloHD before:
>>
>> lsmod | grep lgdt3306a
>> lgdt3306a  28672  -1
>> i2c_mux16384  1 lgdt3306a
>>
>> On disconnect of Hauppauge SoloHD after:
>>
>> lsmod | grep lgdt3306a
>> lgdt3306a  28672  0
>> i2c_mux16384  1 lgdt3306a
>>
>> Signed-off-by: Brad Love 
>> ---
>>  drivers/media/dvb-frontends/lgdt3306a.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
> 
> Brad,
> 
> We won't be able to apply this one.  The symptom that you're trying to
> fix is indicative of some other problem, probably in the em28xx
> driver.  NULL'ing the release callback is not the right thing to do.
> 

Hi Mike,
Why do you nak this perfectly fine patch?
Let me start to explain.

dvb_attach style drivers have an attach function and for unloading a
.release callback.

i2c-style drivers have a probe and a remove function.

Mixed style drivers must be constructed, that either release or remove
is called, never both.
They both do the same thing, but with different signature.


Now checking lgdt3306a driver:

dvb attach style:
In lgdt3306a_attach the release callback is set to lgdt3306a_release and
no remove exists. Fine.

i2c style probe:
struct i2c_driver contains lgdt3306a_probe and lgdt3306a_remove.
lgdt3306a_probe shares code and calls lgdt3306a_attach, but afterwards
the release callback field must be set to NULL.

This is/was done exactly like this in multiple other drivers as long as
they have been multiple style attachable.

Regards
Matthias

> 
>> diff --git a/drivers/media/dvb-frontends/lgdt3306a.c 
>> b/drivers/media/dvb-frontends/lgdt3306a.c
>> index 6356815..d2477ed 100644
>> --- a/drivers/media/dvb-frontends/lgdt3306a.c
>> +++ b/drivers/media/dvb-frontends/lgdt3306a.c
>> @@ -2177,6 +2177,7 @@ static int lgdt3306a_probe(struct i2c_client *client,
>>
>> i2c_set_clientdata(client, fe->demodulator_priv);
>> state = fe->demodulator_priv;
>> +   state->frontend.ops.release = NULL;
>>
>> /* create mux i2c adapter for tuner */
>> state->muxc = i2c_mux_alloc(client->adapter, >dev,
>> --
>> 2.7.4
>>
> 



Re: [PATCH 2/2] lgdt3306a: Fix a double kfree on i2c device remove

2018-01-08 Thread Matthias Schwarzott
Am 05.01.2018 um 15:57 schrieb Brad Love:
> Both lgdt33606a_release and lgdt3306a_remove kfree state, but _release is
> called first, then _remove operates on states members before kfree'ing it.
> This can lead to random oops/GPF/etc on USB disconnect.
> 
lgdt3306a_release does nothing but the kfree. So the exact same effect
can be archived by setting state->frontend.ops.release to NULL. This
need to be done already at probe time I think.
lgdt3306a_remove does this, but too late (after the call to release).

Regards
Matthias

> Signed-off-by: Brad Love 
> ---
>  drivers/media/dvb-frontends/lgdt3306a.c | 8 +++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/dvb-frontends/lgdt3306a.c 
> b/drivers/media/dvb-frontends/lgdt3306a.c
> index d370671..3642e6e 100644
> --- a/drivers/media/dvb-frontends/lgdt3306a.c
> +++ b/drivers/media/dvb-frontends/lgdt3306a.c
> @@ -1768,7 +1768,13 @@ static void lgdt3306a_release(struct dvb_frontend *fe)
>   struct lgdt3306a_state *state = fe->demodulator_priv;
>  
>   dbg_info("\n");
> - kfree(state);
> +
> + /*
> +  * If state->muxc is not NULL, then we are an i2c device
> +  * and lgdt3306a_remove will clean up state
> +  */
> + if (!state->muxc)
> + kfree(state);
>  }
>  
>  static const struct dvb_frontend_ops lgdt3306a_ops;
> 



Re: usb/media/em28xx: use-after-free in dvb_unregister_frontend

2017-11-22 Thread Matthias Schwarzott
Am 21.11.2017 um 14:51 schrieb Andrey Konovalov:
> Hi!
> 
Hi Andrey,

> I've got the following report while fuzzing the kernel with syzkaller.
> 
> On commit e1d1ea549b57790a3d8cf6300e6ef86118d692a3 (4.15-rc1).
> 
> em28xx 1-1:9.0: Disconnecting
> tc90522 1-0015: Toshiba TC90522 attached.
> qm1d1c0042 2-0061: Sharp QM1D1C0042 attached.
> dvbdev: DVB: registering new adapter (1-1:9.0)
> em28xx 1-1:9.0: DVB: registering adapter 0 frontend 0 (Toshiba TC90522
> ISDB-S module)...
> dvbdev: dvb_create_media_entity: media entity 'Toshiba TC90522 ISDB-S
> module' registered.
> dvbdev: dvb_create_media_entity: media entity 'dvb-demux' registered.
> em28xx 1-1:9.0: DVB extension successfully initialized
> em28xx 1-1:9.0: Remote control support is not available for this card.
> em28xx 1-1:9.0: Closing DVB extension
> ==
> BUG: KASAN: use-after-free in dvb_unregister_frontend+0x8f/0xa0
> Read of size 8 at addr 880067853628 by task kworker/0:3/3182
> 
> CPU: 0 PID: 3182 Comm: kworker/0:3 Not tainted 4.14.0-57501-g9284d204d604 #119
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
> Workqueue: usb_hub_wq hub_event
> Call Trace:
>  __dump_stack lib/dump_stack.c:17
>  dump_stack+0xe1/0x157 lib/dump_stack.c:53
>  print_address_description+0x71/0x234 mm/kasan/report.c:252
>  kasan_report_error mm/kasan/report.c:351
>  kasan_report+0x173/0x270 mm/kasan/report.c:409
>  __asan_report_load8_noabort+0x19/0x20 mm/kasan/report.c:430
>  dvb_unregister_frontend+0x8f/0xa0 drivers/media/dvb-core/dvb_frontend.c:2768
>  em28xx_unregister_dvb drivers/media/usb/em28xx/em28xx-dvb.c:1122
>  em28xx_dvb_fini+0x62d/0x8e0 drivers/media/usb/em28xx/em28xx-dvb.c:2129
>  em28xx_close_extension+0x71/0x220 drivers/media/usb/em28xx/em28xx-core.c:1122
>  em28xx_usb_disconnect+0xd7/0x130 drivers/media/usb/em28xx/em28xx-cards.c:3763
>  usb_unbind_interface+0x1b6/0x950 drivers/usb/core/driver.c:423
>  __device_release_driver drivers/base/dd.c:870
>  device_release_driver_internal+0x563/0x630 drivers/base/dd.c:903
>  device_release_driver+0x1e/0x30 drivers/base/dd.c:928
>  bus_remove_device+0x2fc/0x4b0 drivers/base/bus.c:565
>  device_del+0x39f/0xa70 drivers/base/core.c:1984
>  usb_disable_device+0x223/0x710 drivers/usb/core/message.c:1205
>  usb_disconnect+0x285/0x7f0 drivers/usb/core/hub.c:2205
>  hub_port_connect drivers/usb/core/hub.c:4851
>  hub_port_connect_change drivers/usb/core/hub.c:5106
>  port_event drivers/usb/core/hub.c:5212
>  hub_event_impl+0x10f0/0x3440 drivers/usb/core/hub.c:5324
>  hub_event+0x38/0x50 drivers/usb/core/hub.c:5222
>  process_one_work+0x944/0x15f0 kernel/workqueue.c:2112
>  worker_thread+0xef/0x10d0 kernel/workqueue.c:2246
>  kthread+0x367/0x420 kernel/kthread.c:238
>  ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:437
> 

this looks similar to the oops fixed by this patch:

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

Could you try if it fixes your case also?

Regards
Matthias


Re: [PATCH] dvb_frontend: don't use-after-free the frontend struct

2017-11-07 Thread Matthias Schwarzott
Am 07.11.2017 um 14:44 schrieb Mauro Carvalho Chehab:
> diff --git a/drivers/media/dvb-core/dvb_frontend.c 
> b/drivers/media/dvb-core/dvb_frontend.c
> index d485d5f6cc88..3ad83359098b 100644
> --- a/drivers/media/dvb-core/dvb_frontend.c
> +++ b/drivers/media/dvb-core/dvb_frontend.c
> @@ -150,11 +150,8 @@ static void __dvb_frontend_free(struct dvb_frontend *fe)
>  
>   dvb_frontend_invoke_release(fe, fe->ops.release);
>  
> - if (!fepriv)
> - return;
> -
> - kfree(fepriv);
> - fe->frontend_priv = NULL;
> + if (fepriv)
> + kfree(fepriv);

I think the condition is redundant and should be removed.
kfree(NULL) is fine.

>  }
>  
>  static void dvb_frontend_free(struct kref *ref)
> 

Regards
Matthias


[PATCH 15/15] media: MAINTAINERS: add si2165 driver

2017-11-05 Thread Matthias Schwarzott
Silicon Labs Si2165 DVB-C/T demod driver

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index adbf69306e9e..b3dc695bcfa4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12193,6 +12193,14 @@ T: git git://linuxtv.org/anttip/media_tree.git
 S: Maintained
 F: drivers/media/tuners/si2157*
 
+SI2165 MEDIA DRIVER
+M: Matthias Schwarzott <z...@gentoo.org>
+L: linux-media@vger.kernel.org
+W: https://linuxtv.org
+Q: http://patchwork.linuxtv.org/project/linux-media/list/
+S: Maintained
+F: drivers/media/dvb-frontends/si2165*
+
 SI2168 MEDIA DRIVER
 M: Antti Palosaari <cr...@iki.fi>
 L: linux-media@vger.kernel.org
-- 
2.15.0



[PATCH 14/15] si2165: Add DVBv3 wrapper for ber statistics

2017-11-05 Thread Matthias Schwarzott
Add read_ber function that reads from property cache to support DVBv3.
The implementation is inspired by the cx24120 driver.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index ceb5a2bb0dea..2ad6409dd6b1 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -57,6 +57,9 @@ struct si2165_state {
u32 sys_clk;
u32 adc_clk;
 
+   /* DVBv3 stats */
+   u64 ber_prev;
+
bool has_dvbc;
bool has_dvbt;
bool firmware_loaded;
@@ -757,6 +760,12 @@ static int si2165_read_status(struct dvb_frontend *fe, 
enum fe_status *status)
c->post_bit_error.stat[0].uvalue = 0;
c->post_bit_count.stat[0].uvalue = 0;
 
+   /*
+* reset DVBv3 value to deliver a good result
+* for the first call
+*/
+   state->ber_prev = 0;
+
} else {
ret = si2165_readreg8(state, REG_BER_AVAIL, );
if (ret < 0)
@@ -805,6 +814,22 @@ static int si2165_read_snr(struct dvb_frontend *fe, u16 
*snr)
return 0;
 }
 
+static int si2165_read_ber(struct dvb_frontend *fe, u32 *ber)
+{
+   struct si2165_state *state = fe->demodulator_priv;
+   struct dtv_frontend_properties *c = >dtv_property_cache;
+
+   if (c->post_bit_error.stat[0].scale != FE_SCALE_COUNTER) {
+   *ber = 0;
+   return 0;
+   }
+
+   *ber = c->post_bit_error.stat[0].uvalue - state->ber_prev;
+   state->ber_prev = c->post_bit_error.stat[0].uvalue;
+
+   return 0;
+}
+
 static int si2165_set_oversamp(struct si2165_state *state, u32 dvb_rate)
 {
u64 oversamp;
@@ -1123,6 +1148,7 @@ static const struct dvb_frontend_ops si2165_ops = {
.set_frontend  = si2165_set_frontend,
.read_status   = si2165_read_status,
.read_snr  = si2165_read_snr,
+   .read_ber  = si2165_read_ber,
 };
 
 static int si2165_probe(struct i2c_client *client,
-- 
2.15.0



[PATCH 06/15] si2165: improve read_status

2017-11-05 Thread Matthias Schwarzott
Use check_signal register for DVB-T additionally.
For DVB-C use ps_lock additionally.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c  | 41 ++-
 drivers/media/dvb-frontends/si2165_priv.h |  2 ++
 2 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index b2541c1fe554..f8d7595a25d4 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -651,18 +651,47 @@ static int si2165_sleep(struct dvb_frontend *fe)
 static int si2165_read_status(struct dvb_frontend *fe, enum fe_status *status)
 {
int ret;
-   u8 fec_lock = 0;
+   u8 u8tmp;
struct si2165_state *state = fe->demodulator_priv;
+   struct dtv_frontend_properties *p = >dtv_property_cache;
+   u32 delsys = p->delivery_system;
 
-   if (!state->has_dvbt)
-   return -EINVAL;
+   *status = 0;
+
+   switch (delsys) {
+   case SYS_DVBT:
+   /* check fast signal type */
+   ret = si2165_readreg8(state, REG_CHECK_SIGNAL, );
+   if (ret < 0)
+   return ret;
+   switch (u8tmp & 0x3) {
+   case 0: /* searching */
+   case 1: /* nothing */
+   break;
+   case 2: /* digital signal */
+   *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER;
+   break;
+   }
+   break;
+   case SYS_DVBC_ANNEX_A:
+   /* check packet sync lock */
+   ret = si2165_readreg8(state, REG_PS_LOCK, );
+   if (ret < 0)
+   return ret;
+   if (u8tmp & 0x01) {
+   *status |= FE_HAS_SIGNAL;
+   *status |= FE_HAS_CARRIER;
+   *status |= FE_HAS_VITERBI;
+   *status |= FE_HAS_SYNC;
+   }
+   break;
+   }
 
/* check fec_lock */
-   ret = si2165_readreg8(state, REG_FEC_LOCK, _lock);
+   ret = si2165_readreg8(state, REG_FEC_LOCK, );
if (ret < 0)
return ret;
-   *status = 0;
-   if (fec_lock & 0x01) {
+   if (u8tmp & 0x01) {
*status |= FE_HAS_SIGNAL;
*status |= FE_HAS_CARRIER;
*status |= FE_HAS_VITERBI;
diff --git a/drivers/media/dvb-frontends/si2165_priv.h 
b/drivers/media/dvb-frontends/si2165_priv.h
index da8bbda8a4e3..47f18ff69fe5 100644
--- a/drivers/media/dvb-frontends/si2165_priv.h
+++ b/drivers/media/dvb-frontends/si2165_priv.h
@@ -93,6 +93,8 @@ struct si2165_config {
 #define REG_GP_REG0_LSB0x0384
 #define REG_GP_REG0_MSB0x0387
 #define REG_CRC0x037a
+#define REG_CHECK_SIGNAL   0x03a8
+#define REG_PS_LOCK0x0440
 #define REG_BER_PKT0x0470
 #define REG_FEC_LOCK   0x04e0
 #define REG_TS_DATA_MODE   0x04e4
-- 
2.15.0



[PATCH 10/15] cx23885: Use semicolon after assignment instead of comma

2017-11-05 Thread Matthias Schwarzott
End assignments by semicolon instead of comma.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/pci/cx23885/cx23885-dvb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c 
b/drivers/media/pci/cx23885/cx23885-dvb.c
index b33ded461308..67ad04138183 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -1852,8 +1852,8 @@ static int dvb_register(struct cx23885_tsport *port)
/* attach frontend */
memset(_pdata, 0, sizeof(si2165_pdata));
si2165_pdata.fe = >dvb.frontend;
-   si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL,
-   si2165_pdata.ref_freq_hz = 1600,
+   si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL;
+   si2165_pdata.ref_freq_hz = 1600;
memset(, 0, sizeof(struct i2c_board_info));
strlcpy(info.type, "si2165", I2C_NAME_SIZE);
info.addr = 0x64;
-- 
2.15.0



[PATCH 12/15] si2165: add DVBv5 BER statistics

2017-11-05 Thread Matthias Schwarzott
Add support for BER statistics.
Configure a measurement period of 3 packets.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c  | 57 +--
 drivers/media/dvb-frontends/si2165_priv.h | 11 ++
 2 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 777b7d049ae7..1cd2120f5dc4 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -594,8 +594,9 @@ static int si2165_init(struct dvb_frontend *fe)
if (ret < 0)
goto error;
 
-   /* ber_pkt */
-   ret = si2165_writereg16(state, REG_BER_PKT, 0x7530);
+   /* ber_pkt - default 65535 */
+   ret = si2165_writereg16(state, REG_BER_PKT,
+   STATISTICS_PERIOD_PKT_COUNT);
if (ret < 0)
goto error;
 
@@ -642,6 +643,10 @@ static int si2165_init(struct dvb_frontend *fe)
c = >fe.dtv_property_cache;
c->cnr.len = 1;
c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+   c->post_bit_error.len = 1;
+   c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+   c->post_bit_count.len = 1;
+   c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
 
return 0;
 error:
@@ -738,6 +743,54 @@ static int si2165_read_status(struct dvb_frontend *fe, 
enum fe_status *status)
} else
c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
 
+   /* BER */
+   if (*status & FE_HAS_VITERBI) {
+   if (c->post_bit_error.stat[0].scale == FE_SCALE_NOT_AVAILABLE) {
+   /* start new sampling period to get rid of old data*/
+   ret = si2165_writereg8(state, REG_BER_RST, 0x01);
+   if (ret < 0)
+   return ret;
+
+   /* set scale to enter read code on next call */
+   c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
+   c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
+   c->post_bit_error.stat[0].uvalue = 0;
+   c->post_bit_count.stat[0].uvalue = 0;
+
+   } else {
+   ret = si2165_readreg8(state, REG_BER_AVAIL, );
+   if (ret < 0)
+   return ret;
+
+   if (u8tmp & 1) {
+   u32 biterrcnt;
+
+   ret = si2165_readreg24(state, REG_BER_BIT,
+   );
+   if (ret < 0)
+   return ret;
+
+   c->post_bit_error.stat[0].uvalue +=
+   biterrcnt;
+   c->post_bit_count.stat[0].uvalue +=
+   STATISTICS_PERIOD_BIT_COUNT;
+
+   /* start new sampling period */
+   ret = si2165_writereg8(state,
+   REG_BER_RST, 0x01);
+   if (ret < 0)
+   return ret;
+
+   dev_dbg(>client->dev,
+   "post_bit_error=%u post_bit_count=%u\n",
+   biterrcnt, STATISTICS_PERIOD_BIT_COUNT);
+   }
+   }
+   } else {
+   c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+   c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+   }
+
return 0;
 }
 
diff --git a/drivers/media/dvb-frontends/si2165_priv.h 
b/drivers/media/dvb-frontends/si2165_priv.h
index 9d79e86d04c2..8c6fbfe441ff 100644
--- a/drivers/media/dvb-frontends/si2165_priv.h
+++ b/drivers/media/dvb-frontends/si2165_priv.h
@@ -38,6 +38,9 @@ struct si2165_config {
bool inversion;
 };
 
+#define STATISTICS_PERIOD_PKT_COUNT3u
+#define STATISTICS_PERIOD_BIT_COUNT(STATISTICS_PERIOD_PKT_COUNT * 204 * 8)
+
 #define REG_CHIP_MODE  0x
 #define REG_CHIP_REVCODE   0x0023
 #define REV_CHIP_TYPE  0x0118
@@ -95,8 +98,16 @@ struct si2165_config {
 #define REG_GP_REG0_MSB0x0387
 #define REG_CRC0x037a
 #define REG_CHECK_SIGNAL   0x03a8
+#define REG_CBER_RST   0x0424
+#define REG_CBER_BIT   0x0428
+#define REG_CBER_ERR   0x0430
+#define REG_CBER_AVAIL 0x0434
 #define REG_PS_LOCK0x0440
+#define REG_UNCOR_CNT  0x0468
+#define REG_BER_RST0x046c
 #d

[PATCH 13/15] si2165: add DVBv3 wrapper for C/N statistics

2017-11-05 Thread Matthias Schwarzott
Add read_snr function that reads from property cache to support DVBv3.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 1cd2120f5dc4..ceb5a2bb0dea 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -794,6 +794,17 @@ static int si2165_read_status(struct dvb_frontend *fe, 
enum fe_status *status)
return 0;
 }
 
+static int si2165_read_snr(struct dvb_frontend *fe, u16 *snr)
+{
+   struct dtv_frontend_properties *c = >dtv_property_cache;
+
+   if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL)
+   *snr = div_s64(c->cnr.stat[0].svalue, 100);
+   else
+   *snr = 0;
+   return 0;
+}
+
 static int si2165_set_oversamp(struct si2165_state *state, u32 dvb_rate)
 {
u64 oversamp;
@@ -,6 +1122,7 @@ static const struct dvb_frontend_ops si2165_ops = {
 
.set_frontend  = si2165_set_frontend,
.read_status   = si2165_read_status,
+   .read_snr  = si2165_read_snr,
 };
 
 static int si2165_probe(struct i2c_client *client,
-- 
2.15.0



[PATCH 11/15] si2165: add DVBv5 C/N statistics for DVB-C

2017-11-05 Thread Matthias Schwarzott
Add C/N statistics in dB to read_status (DVBv5).

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c  | 43 +--
 drivers/media/dvb-frontends/si2165_priv.h |  1 +
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 30ceba664f5f..777b7d049ae7 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -116,6 +116,17 @@ static int si2165_readreg16(struct si2165_state *state,
return ret;
 }
 
+static int si2165_readreg24(struct si2165_state *state,
+   const u16 reg, u32 *val)
+{
+   u8 buf[3];
+
+   int ret = si2165_read(state, reg, buf, 3);
+   *val = buf[0] | buf[1] << 8 | buf[2] << 16;
+   dev_dbg(>client->dev, "reg read: R(0x%04x)=0x%06x\n", reg, *val);
+   return ret;
+}
+
 static int si2165_writereg8(struct si2165_state *state, const u16 reg, u8 val)
 {
return regmap_write(state->regmap, reg, val);
@@ -518,6 +529,7 @@ static int si2165_init(struct dvb_frontend *fe)
 {
int ret = 0;
struct si2165_state *state = fe->demodulator_priv;
+   struct dtv_frontend_properties *c = >dtv_property_cache;
u8 val;
u8 patch_version = 0x00;
 
@@ -627,6 +639,10 @@ static int si2165_init(struct dvb_frontend *fe)
if (ret < 0)
return ret;
 
+   c = >fe.dtv_property_cache;
+   c->cnr.len = 1;
+   c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+
return 0;
 error:
return ret;
@@ -652,9 +668,10 @@ static int si2165_read_status(struct dvb_frontend *fe, 
enum fe_status *status)
 {
int ret;
u8 u8tmp;
+   u32 u32tmp;
struct si2165_state *state = fe->demodulator_priv;
-   struct dtv_frontend_properties *p = >dtv_property_cache;
-   u32 delsys = p->delivery_system;
+   struct dtv_frontend_properties *c = >dtv_property_cache;
+   u32 delsys = c->delivery_system;
 
*status = 0;
 
@@ -699,6 +716,28 @@ static int si2165_read_status(struct dvb_frontend *fe, 
enum fe_status *status)
*status |= FE_HAS_LOCK;
}
 
+   /* CNR */
+   if (delsys == SYS_DVBC_ANNEX_A && *status & FE_HAS_VITERBI) {
+   ret = si2165_readreg24(state, REG_C_N, );
+   if (ret < 0)
+   return ret;
+   /*
+* svalue =
+* 1000 * c_n/dB =
+* 1000 * 10 * log10(2^24 / regval) =
+* 1000 * 10 * (log10(2^24) - log10(regval)) =
+* 1000 * 10 * (intlog10(2^24) - intlog10(regval)) / 2^24
+*
+* intlog10(x) = log10(x) * 2^24
+* intlog10(2^24) = log10(2^24) * 2^24 = 121210686
+*/
+   u32tmp = (1000 * 10 * (121210686 - (u64)intlog10(u32tmp)))
+   >> 24;
+   c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
+   c->cnr.stat[0].svalue = u32tmp;
+   } else
+   c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+
return 0;
 }
 
diff --git a/drivers/media/dvb-frontends/si2165_priv.h 
b/drivers/media/dvb-frontends/si2165_priv.h
index 47f18ff69fe5..9d79e86d04c2 100644
--- a/drivers/media/dvb-frontends/si2165_priv.h
+++ b/drivers/media/dvb-frontends/si2165_priv.h
@@ -74,6 +74,7 @@ struct si2165_config {
 #define REG_KP_LOCK0x023a
 #define REG_UNKNOWN_24C0x024c
 #define REG_CENTRAL_TAP0x0261
+#define REG_C_N0x026c
 #define REG_EQ_AUTO_CONTROL0x0278
 #define REG_UNKNOWN_27C0x027c
 #define REG_START_SYNCHRO  0x02e0
-- 
2.15.0



[PATCH 03/15] si2165: Make checkpatch happy

2017-11-05 Thread Matthias Schwarzott
Fix almost all of checkpatch --strict warnings.

The remaining warnings are about:
* macro REG16 (should be enclosed in parentheses)
* macro REG16 (Macro argument reuse)

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c  | 87 ---
 drivers/media/dvb-frontends/si2165.h  | 37 ++---
 drivers/media/dvb-frontends/si2165_priv.h | 35 +++--
 drivers/media/pci/cx23885/cx23885-dvb.c   |  2 +-
 drivers/media/usb/cx231xx/cx231xx-dvb.c   |  4 +-
 5 files changed, 86 insertions(+), 79 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 7110b3b37f23..6b22d079ecef 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -63,11 +63,12 @@ struct si2165_state {
 };
 
 static int si2165_write(struct si2165_state *state, const u16 reg,
-  const u8 *src, const int count)
+   const u8 *src, const int count)
 {
int ret;
 
-   dev_dbg(>client->dev, "i2c write: reg: 0x%04x, data: %*ph\n", 
reg, count, src);
+   dev_dbg(>client->dev, "i2c write: reg: 0x%04x, data: %*ph\n",
+   reg, count, src);
 
ret = regmap_bulk_write(state->regmap, reg, src, count);
 
@@ -88,13 +89,14 @@ static int si2165_read(struct si2165_state *state,
return ret;
}
 
-   dev_dbg(>client->dev, "i2c read: reg: 0x%04x, data: %*ph\n", 
reg, count, val);
+   dev_dbg(>client->dev, "i2c read: reg: 0x%04x, data: %*ph\n",
+   reg, count, val);
 
return 0;
 }
 
 static int si2165_readreg8(struct si2165_state *state,
-  const u16 reg, u8 *val)
+  const u16 reg, u8 *val)
 {
unsigned int val_tmp;
int ret = regmap_read(state->regmap, reg, _tmp);
@@ -104,7 +106,7 @@ static int si2165_readreg8(struct si2165_state *state,
 }
 
 static int si2165_readreg16(struct si2165_state *state,
-  const u16 reg, u16 *val)
+   const u16 reg, u16 *val)
 {
u8 buf[2];
 
@@ -161,7 +163,9 @@ static int si2165_writereg_mask8(struct si2165_state 
*state, const u16 reg,
return si2165_writereg8(state, reg, val);
 }
 
-#define REG16(reg, val) { (reg), (val) & 0xff }, { (reg)+1, (val)>>8 & 0xff }
+#define REG16(reg, val) \
+   { (reg), (val) & 0xff }, \
+   { (reg) + 1, (val) >> 8 & 0xff }
 struct si2165_reg_value_pair {
u16 reg;
u8 val;
@@ -191,7 +195,7 @@ static int si2165_get_tune_settings(struct dvb_frontend *fe,
 
 static int si2165_init_pll(struct si2165_state *state)
 {
-   u32 ref_freq_Hz = state->config.ref_freq_Hz;
+   u32 ref_freq_hz = state->config.ref_freq_hz;
u8 divr = 1; /* 1..7 */
u8 divp = 1; /* only 1 or 4 */
u8 divn = 56; /* 1..63 */
@@ -203,7 +207,7 @@ static int si2165_init_pll(struct si2165_state *state)
 * hardcoded values can be deleted if calculation is verified
 * or it yields the same values as the windows driver
 */
-   switch (ref_freq_Hz) {
+   switch (ref_freq_hz) {
case 1600u:
divn = 56;
break;
@@ -214,23 +218,23 @@ static int si2165_init_pll(struct si2165_state *state)
break;
default:
/* ref_freq / divr must be between 4 and 16 MHz */
-   if (ref_freq_Hz > 1600u)
+   if (ref_freq_hz > 1600u)
divr = 2;
 
/*
 * now select divn and divp such that
 * fvco is in 1624..1824 MHz
 */
-   if (162400u * divr > ref_freq_Hz * 2u * 63u)
+   if (162400u * divr > ref_freq_hz * 2u * 63u)
divp = 4;
 
/* is this already correct regarding rounding? */
-   divn = 162400u * divr / (ref_freq_Hz * 2u * divp);
+   divn = 162400u * divr / (ref_freq_hz * 2u * divp);
break;
}
 
/* adc_clk and sys_clk depend on xtal and pll settings */
-   state->fvco_hz = ref_freq_Hz / divr
+   state->fvco_hz = ref_freq_hz / divr
* 2u * divn * divp;
state->adc_clk = state->fvco_hz / (divm * 4u);
state->sys_clk = state->fvco_hz / (divl * 2u);
@@ -272,7 +276,8 @@ static int si2165_wait_init_done(struct si2165_state *state)
 }
 
 static int si2165_upload_firmware_block(struct si2165_state *state,
-   const u8 *data, u32 len, u32 *poffset, u32 block_count)
+   const u8 *data, u32 len, u32 *poffset,
+   u32 block_count)
 {
int ret;
u8 buf_ctrl[4] = { 0x00, 0x00, 0x00, 0xc0 };
@@ -286,

[PATCH 08/15] si2165: Use constellation from property cache instead of hardcoded QAM256

2017-11-05 Thread Matthias Schwarzott
Use constellation from property cache instead of always setting it to
QAM256.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 29 ++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 0b801bad5802..30ceba664f5f 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -834,13 +834,11 @@ static const struct si2165_reg_value_pair dvbc_regs[] = {
{ REG_KP_LOCK, 0x05 },
{ REG_CENTRAL_TAP, 0x09 },
REG16(REG_UNKNOWN_350, 0x3e80),
-   { REG_REQ_CONSTELLATION, 0x00 },
 
{ REG_AUTO_RESET, 0x01 },
REG16(REG_UNKNOWN_24C, 0x),
REG16(REG_UNKNOWN_27C, 0x),
{ REG_SWEEP_STEP, 0x03 },
-   { REG_REQ_CONSTELLATION, 0x0b },
{ REG_AGC_IF_TRI, 0x00 },
 };
 
@@ -850,6 +848,7 @@ static int si2165_set_frontend_dvbc(struct dvb_frontend *fe)
int ret;
struct dtv_frontend_properties *p = >dtv_property_cache;
const u32 dvb_rate = p->symbol_rate;
+   u8 u8tmp;
 
if (!state->has_dvbc)
return -EINVAL;
@@ -866,6 +865,31 @@ static int si2165_set_frontend_dvbc(struct dvb_frontend 
*fe)
if (ret < 0)
return ret;
 
+   switch (p->modulation) {
+   case QPSK:
+   u8tmp = 0x3;
+   break;
+   case QAM_16:
+   u8tmp = 0x7;
+   break;
+   case QAM_32:
+   u8tmp = 0x8;
+   break;
+   case QAM_64:
+   u8tmp = 0x9;
+   break;
+   case QAM_128:
+   u8tmp = 0xa;
+   break;
+   case QAM_256:
+   default:
+   u8tmp = 0xb;
+   break;
+   }
+   ret = si2165_writereg8(state, REG_REQ_CONSTELLATION, u8tmp);
+   if (ret < 0)
+   return ret;
+
ret = si2165_writereg32(state, REG_LOCK_TIMEOUT, 0x007a1200);
if (ret < 0)
return ret;
@@ -981,7 +1005,6 @@ static const struct dvb_frontend_ops si2165_ops = {
FE_CAN_QAM_64 |
FE_CAN_QAM_128 |
FE_CAN_QAM_256 |
-   FE_CAN_QAM_AUTO |
FE_CAN_GUARD_INTERVAL_AUTO |
FE_CAN_HIERARCHY_AUTO |
FE_CAN_MUTE_TS |
-- 
2.15.0



[PATCH 04/15] si2165: define register macros

2017-11-05 Thread Matthias Schwarzott
Convert register numbers to macros.

Correctness verified by comparing the disassembly before and after.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c  | 206 +++---
 drivers/media/dvb-frontends/si2165_priv.h |  65 ++
 2 files changed, 169 insertions(+), 102 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 6b22d079ecef..0f5325798bd2 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -239,18 +239,18 @@ static int si2165_init_pll(struct si2165_state *state)
state->adc_clk = state->fvco_hz / (divm * 4u);
state->sys_clk = state->fvco_hz / (divl * 2u);
 
-   /* write pll registers 0x00a0..0x00a3 at once */
+   /* write all 4 pll registers 0x00a0..0x00a3 at once */
buf[0] = divl;
buf[1] = divm;
buf[2] = (divn & 0x3f) | ((divp == 1) ? 0x40 : 0x00) | 0x80;
buf[3] = divr;
-   return si2165_write(state, 0x00a0, buf, 4);
+   return si2165_write(state, REG_PLL_DIVL, buf, 4);
 }
 
 static int si2165_adjust_pll_divl(struct si2165_state *state, u8 divl)
 {
state->sys_clk = state->fvco_hz / (divl * 2u);
-   return si2165_writereg8(state, 0x00a0, divl); /* pll_divl */
+   return si2165_writereg8(state, REG_PLL_DIVL, divl);
 }
 
 static u32 si2165_get_fe_clk(struct si2165_state *state)
@@ -266,7 +266,7 @@ static int si2165_wait_init_done(struct si2165_state *state)
int i;
 
for (i = 0; i < 3; ++i) {
-   si2165_readreg8(state, 0x0054, );
+   si2165_readreg8(state, REG_INIT_DONE, );
if (val == 0x01)
return 0;
usleep_range(1000, 5);
@@ -315,17 +315,18 @@ static int si2165_upload_firmware_block(struct 
si2165_state *state,
 
buf_ctrl[0] = wordcount - 1;
 
-   ret = si2165_write(state, 0x0364, buf_ctrl, 4);
+   ret = si2165_write(state, REG_DCOM_CONTROL_BYTE, buf_ctrl, 4);
if (ret < 0)
goto error;
-   ret = si2165_write(state, 0x0368, data + offset + 4, 4);
+   ret = si2165_write(state, REG_DCOM_ADDR, data + offset + 4, 4);
if (ret < 0)
goto error;
 
offset += 8;
 
while (wordcount > 0) {
-   ret = si2165_write(state, 0x36c, data + offset, 4);
+   ret = si2165_write(state, REG_DCOM_DATA,
+  data + offset, 4);
if (ret < 0)
goto error;
wordcount--;
@@ -415,26 +416,26 @@ static int si2165_upload_firmware(struct si2165_state 
*state)
 
/* start uploading fw */
/* boot/wdog status */
-   ret = si2165_writereg8(state, 0x0341, 0x00);
+   ret = si2165_writereg8(state, REG_WDOG_AND_BOOT, 0x00);
if (ret < 0)
goto error;
/* reset */
-   ret = si2165_writereg8(state, 0x00c0, 0x00);
+   ret = si2165_writereg8(state, REG_RST_ALL, 0x00);
if (ret < 0)
goto error;
/* boot/wdog status */
-   ret = si2165_readreg8(state, 0x0341, val);
+   ret = si2165_readreg8(state, REG_WDOG_AND_BOOT, val);
if (ret < 0)
goto error;
 
/* enable reset on error */
-   ret = si2165_readreg8(state, 0x035c, val);
+   ret = si2165_readreg8(state, REG_EN_RST_ERROR, val);
if (ret < 0)
goto error;
-   ret = si2165_readreg8(state, 0x035c, val);
+   ret = si2165_readreg8(state, REG_EN_RST_ERROR, val);
if (ret < 0)
goto error;
-   ret = si2165_writereg8(state, 0x035c, 0x02);
+   ret = si2165_writereg8(state, REG_EN_RST_ERROR, 0x02);
if (ret < 0)
goto error;
 
@@ -448,12 +449,12 @@ static int si2165_upload_firmware(struct si2165_state 
*state)
if (ret < 0)
goto error;
 
-   ret = si2165_writereg8(state, 0x0344, patch_version);
+   ret = si2165_writereg8(state, REG_PATCH_VERSION, patch_version);
if (ret < 0)
goto error;
 
/* reset crc */
-   ret = si2165_writereg8(state, 0x0379, 0x01);
+   ret = si2165_writereg8(state, REG_RST_CRC, 0x01);
if (ret)
goto error;
 
@@ -466,7 +467,7 @@ static int si2165_upload_firmware(struct si2165_state 
*state)
}
 
/* read crc */
-   ret = si2165_readreg16(state, 0x037a, );
+   ret = si2165_readreg16(state, REG_CRC, );
if (ret)
goto error;
 
@@ -491,12 +492,12 @@ static int si2165_upload_firmware(struct si2165_state 
*state)
}
 
/* reset watchdog error register */
-   ret = si2165_writereg_mask8(st

[PATCH 05/15] si2165: move ts parallel mode setting to the ts init code

2017-11-05 Thread Matthias Schwarzott
The TS parallel mode setting should be where all other TS settings are written.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 0f5325798bd2..b2541c1fe554 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -621,6 +621,9 @@ static int si2165_init(struct dvb_frontend *fe)
if (ret < 0)
return ret;
ret = si2165_writereg8(state, REG_TS_CLK_MODE, 0x01);
+   if (ret < 0)
+   return ret;
+   ret = si2165_writereg8(state, REG_TS_PARALLEL_MODE, 0x00);
if (ret < 0)
return ret;
 
@@ -723,7 +726,6 @@ static int si2165_set_if_freq_shift(struct si2165_state 
*state)
 static const struct si2165_reg_value_pair dvbt_regs[] = {
/* standard = DVB-T */
{ REG_DVB_STANDARD, 0x01 },
-   { REG_TS_PARALLEL_MODE, 0x00 },
/* impulsive_noise_remover */
{ REG_IMPULSIVE_NOISE_REM, 0x01 },
{ REG_AUTO_RESET, 0x00 },
@@ -786,7 +788,6 @@ static int si2165_set_frontend_dvbt(struct dvb_frontend *fe)
 static const struct si2165_reg_value_pair dvbc_regs[] = {
/* standard = DVB-C */
{ REG_DVB_STANDARD, 0x05 },
-   { REG_TS_PARALLEL_MODE, 0x00 },
 
/* agc2 */
{ REG_AGC2_MIN, 0x50 },
-- 
2.15.0



[PATCH 02/15] si2165: Convert debug printk to dev_dbg

2017-11-05 Thread Matthias Schwarzott
Removed module parameter debug and the conditions based on it.
Now it can be configured via dynamic debug.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 79 +++-
 1 file changed, 15 insertions(+), 64 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 9471846ad424..7110b3b37f23 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -62,58 +62,12 @@ struct si2165_state {
bool firmware_loaded;
 };
 
-#define DEBUG_OTHER0x01
-#define DEBUG_I2C_WRITE0x02
-#define DEBUG_I2C_READ 0x04
-#define DEBUG_REG_READ 0x08
-#define DEBUG_REG_WRITE0x10
-#define DEBUG_FW_LOAD  0x20
-
-static int debug = 0x00;
-
-#define dprintk(args...) \
-   do { \
-   if (debug & DEBUG_OTHER) \
-   printk(KERN_DEBUG "si2165: " args); \
-   } while (0)
-
-#define deb_i2c_write(args...) \
-   do { \
-   if (debug & DEBUG_I2C_WRITE) \
-   printk(KERN_DEBUG "si2165: i2c write: " args); \
-   } while (0)
-
-#define deb_i2c_read(args...) \
-   do { \
-   if (debug & DEBUG_I2C_READ) \
-   printk(KERN_DEBUG "si2165: i2c read: " args); \
-   } while (0)
-
-#define deb_readreg(args...) \
-   do { \
-   if (debug & DEBUG_REG_READ) \
-   printk(KERN_DEBUG "si2165: reg read: " args); \
-   } while (0)
-
-#define deb_writereg(args...) \
-   do { \
-   if (debug & DEBUG_REG_WRITE) \
-   printk(KERN_DEBUG "si2165: reg write: " args); \
-   } while (0)
-
-#define deb_fw_load(args...) \
-   do { \
-   if (debug & DEBUG_FW_LOAD) \
-   printk(KERN_DEBUG "si2165: fw load: " args); \
-   } while (0)
-
 static int si2165_write(struct si2165_state *state, const u16 reg,
   const u8 *src, const int count)
 {
int ret;
 
-   if (debug & DEBUG_I2C_WRITE)
-   deb_i2c_write("reg: 0x%04x, data: %*ph\n", reg, count, src);
+   dev_dbg(>client->dev, "i2c write: reg: 0x%04x, data: %*ph\n", 
reg, count, src);
 
ret = regmap_bulk_write(state->regmap, reg, src, count);
 
@@ -134,8 +88,7 @@ static int si2165_read(struct si2165_state *state,
return ret;
}
 
-   if (debug & DEBUG_I2C_READ)
-   deb_i2c_read("reg: 0x%04x, data: %*ph\n", reg, count, val);
+   dev_dbg(>client->dev, "i2c read: reg: 0x%04x, data: %*ph\n", 
reg, count, val);
 
return 0;
 }
@@ -146,7 +99,7 @@ static int si2165_readreg8(struct si2165_state *state,
unsigned int val_tmp;
int ret = regmap_read(state->regmap, reg, _tmp);
*val = (u8)val_tmp;
-   deb_readreg("R(0x%04x)=0x%02x\n", reg, *val);
+   dev_dbg(>client->dev, "reg read: R(0x%04x)=0x%02x\n", reg, *val);
return ret;
 }
 
@@ -157,7 +110,7 @@ static int si2165_readreg16(struct si2165_state *state,
 
int ret = si2165_read(state, reg, buf, 2);
*val = buf[0] | buf[1] << 8;
-   deb_readreg("R(0x%04x)=0x%04x\n", reg, *val);
+   dev_dbg(>client->dev, "reg read: R(0x%04x)=0x%04x\n", reg, *val);
return ret;
 }
 
@@ -332,12 +285,12 @@ static int si2165_upload_firmware_block(struct 
si2165_state *state,
if (len % 4 != 0)
return -EINVAL;
 
-   deb_fw_load(
-   "si2165_upload_firmware_block called with len=0x%x offset=0x%x 
blockcount=0x%x\n",
+   dev_dbg(>client->dev,
+   "fw load: si2165_upload_firmware_block called with len=0x%x 
offset=0x%x blockcount=0x%x\n",
len, offset, block_count);
while (offset+12 <= len && cur_block < block_count) {
-   deb_fw_load(
-   "si2165_upload_firmware_block in while len=0x%x 
offset=0x%x cur_block=0x%x blockcount=0x%x\n",
+   dev_dbg(>client->dev,
+   "fw load: si2165_upload_firmware_block in while 
len=0x%x offset=0x%x cur_block=0x%x blockcount=0x%x\n",
len, offset, cur_block, block_count);
wordcount = data[offset];
if (wordcount < 1 || data[offset+1] ||
@@ -376,14 +329,15 @@ static int si2165_upload_firmware_block(struct 
si2165_state *state,
cur_block++;
}
 
-   deb_fw_load(
-   "si2165_upload_firmware_block after while len=0x%x offset=0x%x 
cur_block=0x%x blockcount=0x%x\n",
+   dev_dbg(>client->dev,
+   "fw load: si2165_upload_

[PATCH 09/15] cx231xx: Use semicolon after assignment instead of comma

2017-11-05 Thread Matthias Schwarzott
End assignments by semicolon instead of comma.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/usb/cx231xx/cx231xx-dvb.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c 
b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index 4e462edf044f..5cee642dff06 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -762,8 +762,8 @@ static int dvb_init(struct cx231xx *dev)
/* attach demod */
memset(_pdata, 0, sizeof(si2165_pdata));
si2165_pdata.fe = >dvb->frontend;
-   si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL,
-   si2165_pdata.ref_freq_hz = 1600,
+   si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL;
+   si2165_pdata.ref_freq_hz = 1600;
 
memset(, 0, sizeof(struct i2c_board_info));
strlcpy(info.type, "si2165", I2C_NAME_SIZE);
@@ -809,8 +809,8 @@ static int dvb_init(struct cx231xx *dev)
/* attach demod */
memset(_pdata, 0, sizeof(si2165_pdata));
si2165_pdata.fe = >dvb->frontend;
-   si2165_pdata.chip_mode = SI2165_MODE_PLL_EXT,
-   si2165_pdata.ref_freq_hz = 2400,
+   si2165_pdata.chip_mode = SI2165_MODE_PLL_EXT;
+   si2165_pdata.ref_freq_hz = 2400;
 
memset(, 0, sizeof(struct i2c_board_info));
strlcpy(info.type, "si2165", I2C_NAME_SIZE);
-- 
2.15.0



[PATCH 07/15] si2165: Write const value for lock timeout

2017-11-05 Thread Matthias Schwarzott
The lock timeout should not depend on the bandwidth.
It should be either constant or depend on xtal frequency.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index f8d7595a25d4..0b801bad5802 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -850,7 +850,6 @@ static int si2165_set_frontend_dvbc(struct dvb_frontend *fe)
int ret;
struct dtv_frontend_properties *p = >dtv_property_cache;
const u32 dvb_rate = p->symbol_rate;
-   const u32 bw_hz = p->bandwidth_hz;
 
if (!state->has_dvbc)
return -EINVAL;
@@ -867,7 +866,7 @@ static int si2165_set_frontend_dvbc(struct dvb_frontend *fe)
if (ret < 0)
return ret;
 
-   ret = si2165_writereg32(state, REG_LOCK_TIMEOUT, bw_hz);
+   ret = si2165_writereg32(state, REG_LOCK_TIMEOUT, 0x007a1200);
if (ret < 0)
return ret;
 
-- 
2.15.0



[PATCH 01/15] si2165: Remove redundant KBUILD_MODNAME from dev_* logging

2017-11-05 Thread Matthias Schwarzott
Remove redundant repeated module name from messages.

Before:
  si2165 8-0064: si2165: fw load finished

After:
  si2165 8-0064: fw load finished

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 69 
 1 file changed, 31 insertions(+), 38 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 528b82a5dd46..9471846ad424 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -1,7 +1,7 @@
 /*
  *  Driver for Silicon Labs Si2161 DVB-T and Si2165 DVB-C/-T Demodulator
  *
- *  Copyright (C) 2013-2014 Matthias Schwarzott <z...@gentoo.org>
+ *  Copyright (C) 2013-2017 Matthias Schwarzott <z...@gentoo.org>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -314,8 +314,7 @@ static int si2165_wait_init_done(struct si2165_state *state)
return 0;
usleep_range(1000, 5);
}
-   dev_err(>client->dev, "%s: init_done was not set\n",
-   KBUILD_MODNAME);
+   dev_err(>client->dev, "init_done was not set\n");
return ret;
 }
 
@@ -344,15 +343,15 @@ static int si2165_upload_firmware_block(struct 
si2165_state *state,
if (wordcount < 1 || data[offset+1] ||
data[offset+2] || data[offset+3]) {
dev_warn(>client->dev,
-"%s: bad fw data[0..3] = %*ph\n",
-   KBUILD_MODNAME, 4, data);
+"bad fw data[0..3] = %*ph\n",
+4, data);
return -EINVAL;
}
 
if (offset + 8 + wordcount * 4 > len) {
dev_warn(>client->dev,
-"%s: len is too small for block len=%d, 
wordcount=%d\n",
-   KBUILD_MODNAME, len, wordcount);
+"len is too small for block len=%d, 
wordcount=%d\n",
+   len, wordcount);
return -EINVAL;
}
 
@@ -413,43 +412,40 @@ static int si2165_upload_firmware(struct si2165_state 
*state)
fw_file = SI2165_FIRMWARE_REV_D;
break;
default:
-   dev_info(>client->dev, "%s: no firmware file for 
revision=%d\n",
-   KBUILD_MODNAME, state->chip_revcode);
+   dev_info(>client->dev, "no firmware file for 
revision=%d\n",
+   state->chip_revcode);
return 0;
}
 
/* request the firmware, this will block and timeout */
ret = request_firmware(, fw_file, >client->dev);
if (ret) {
-   dev_warn(>client->dev, "%s: firmware file '%s' not 
found\n",
-   KBUILD_MODNAME, fw_file);
+   dev_warn(>client->dev, "firmware file '%s' not found\n",
+   fw_file);
goto error;
}
 
data = fw->data;
len = fw->size;
 
-   dev_info(>client->dev, "%s: downloading firmware from file '%s' 
size=%d\n",
-   KBUILD_MODNAME, fw_file, len);
+   dev_info(>client->dev, "downloading firmware from file '%s' 
size=%d\n",
+   fw_file, len);
 
if (len % 4 != 0) {
-   dev_warn(>client->dev, "%s: firmware size is not 
multiple of 4\n",
-   KBUILD_MODNAME);
+   dev_warn(>client->dev, "firmware size is not multiple of 
4\n");
ret = -EINVAL;
goto error;
}
 
/* check header (8 bytes) */
if (len < 8) {
-   dev_warn(>client->dev, "%s: firmware header is 
missing\n",
-   KBUILD_MODNAME);
+   dev_warn(>client->dev, "firmware header is missing\n");
ret = -EINVAL;
goto error;
}
 
if (data[0] != 1 || data[1] != 0) {
-   dev_warn(>client->dev, "%s: firmware file version is 
wrong\n",
-   KBUILD_MODNAME);
+   dev_warn(>client->dev, "firmware file version is 
wrong\n");
ret = -EINVAL;
goto error;
}
@@ -486,8 +482,8 @@ static int si2165_upload_firmware(struct si2165_state 
*state)
/* start right after the header */
offset = 8;
 
-   dev_info(>client->dev, "%s: si2165_upload_fir

[PATCH] build: add fwnode_property_get_reference_args if not defined

2017-11-05 Thread Matthias Schwarzott
Add function dummy that returns -ENODATA.
Copied struct fwnode_reference_args from include/linux/fwnode.h.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 v4l/compat.h  | 19 +++
 v4l/scripts/make_config_compat.pl |  1 +
 2 files changed, 20 insertions(+)

diff --git a/v4l/compat.h b/v4l/compat.h
index f788e79..eec2974 100644
--- a/v4l/compat.h
+++ b/v4l/compat.h
@@ -2212,4 +2212,23 @@ static inline void timer_setup(struct timer_list *timer,
 
 #endif
 
+#ifdef NEED_FWNODE_PROP_GET_REF_ARGS
+#define NR_FWNODE_REFERENCE_ARGS   8
+
+struct fwnode_reference_args {
+struct fwnode_handle *fwnode;
+/* unsigned int nargs; */
+unsigned int args[NR_FWNODE_REFERENCE_ARGS];
+};
+
+static inline int fwnode_property_get_reference_args(const struct 
fwnode_handle *fwnode,
+  const char *prop, const char *nargs_prop,
+  unsigned int nargs, unsigned int index,
+  struct fwnode_reference_args *args)
+{
+return -ENODATA;
+}
+
+#endif
+
 #endif /*  _COMPAT_H */
diff --git a/v4l/scripts/make_config_compat.pl 
b/v4l/scripts/make_config_compat.pl
index 62eb6b9..9752ddf 100644
--- a/v4l/scripts/make_config_compat.pl
+++ b/v4l/scripts/make_config_compat.pl
@@ -707,6 +707,7 @@ sub check_other_dependencies()
check_files_for_func("U32_MAX", "NEED_U32_MAX", 
"include/linux/kernel.h");
check_files_for_func("bsearch", "NEED_BSEARCH", 
"include/linux/bsearch.h");
check_files_for_func("timer_setup", "NEED_TIMER_SETUP", 
"include/linux/timer.h");
+   check_files_for_func("fwnode_property_get_reference_args", 
"NEED_FWNODE_PROP_GET_REF_ARGS", "include/linux/property.h");
 
# For tests for uapi-dependent logic
check_files_for_func_uapi("usb_endpoint_maxp", 
"NEED_USB_ENDPOINT_MAXP", "usb/ch9.h");
-- 
2.15.0



[PATCH] build: Add support for timer_setup

2017-11-04 Thread Matthias Schwarzott
Literally copied the implementation from kernel
commit 686fef928bba6be13 (timer: Prepare to change timer callback argument type)

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 v4l/compat.h  | 17 +
 v4l/scripts/make_config_compat.pl |  1 +
 2 files changed, 18 insertions(+)

diff --git a/v4l/compat.h b/v4l/compat.h
index 3504288..f788e79 100644
--- a/v4l/compat.h
+++ b/v4l/compat.h
@@ -2195,4 +2195,21 @@ static inline void *bsearch(const void *key, const void 
*base, size_t num, size_
 }
 #endif
 
+#ifdef NEED_TIMER_SETUP
+#define TIMER_DATA_TYPEunsigned long
+#define TIMER_FUNC_TYPEvoid (*)(TIMER_DATA_TYPE)
+
+static inline void timer_setup(struct timer_list *timer,
+  void (*callback)(struct timer_list *),
+  unsigned int flags)
+{
+   __setup_timer(timer, (TIMER_FUNC_TYPE)callback,
+ (TIMER_DATA_TYPE)timer, flags);
+}
+
+#define from_timer(var, callback_timer, timer_fieldname) \
+   container_of(callback_timer, typeof(*var), timer_fieldname)
+
+#endif
+
 #endif /*  _COMPAT_H */
diff --git a/v4l/scripts/make_config_compat.pl 
b/v4l/scripts/make_config_compat.pl
index 8ebeea3..62eb6b9 100644
--- a/v4l/scripts/make_config_compat.pl
+++ b/v4l/scripts/make_config_compat.pl
@@ -706,6 +706,7 @@ sub check_other_dependencies()
check_files_for_func("annotate_reachable", "NEED_ANNOTATE_REACHABLE", 
"include/linux/compiler.h");
check_files_for_func("U32_MAX", "NEED_U32_MAX", 
"include/linux/kernel.h");
check_files_for_func("bsearch", "NEED_BSEARCH", 
"include/linux/bsearch.h");
+   check_files_for_func("timer_setup", "NEED_TIMER_SETUP", 
"include/linux/timer.h");
 
# For tests for uapi-dependent logic
check_files_for_func_uapi("usb_endpoint_maxp", 
"NEED_USB_ENDPOINT_MAXP", "usb/ch9.h");
-- 
2.15.0



[PATCH] em28xx: Fix use-after-free when disconnecting

2017-10-30 Thread Matthias Schwarzott
Fix bug by moving the i2c_unregister_device calls after deregistration
of dvb frontend.

The new style i2c drivers already destroys the frontend object at
i2c_unregister_device time.
When the dvb frontend is unregistered afterwards it leads to this oops:

  [ 6058.866459] BUG: unable to handle kernel NULL pointer dereference at 
01f8
  [ 6058.866578] IP: dvb_frontend_stop+0x30/0xd0 [dvb_core]
  [ 6058.866644] PGD 0
  [ 6058.866646] P4D 0

  [ 6058.866726] Oops:  [#1] SMP
  [ 6058.866768] Modules linked in: rc_pinnacle_pctv_hd(O) em28xx_rc(O) 
si2157(O) si2168(O) em28xx_dvb(O) em28xx(O) si2165(O) a8293(O) tda10071(O) 
tea5767(O) tuner(O) cx23885(O) tda18271(O) videobuf2_dvb(O) videobuf2_dma_sg(O) 
m88ds3103(O) tveeprom(O) cx2341x(O) v4l2_common(O) dvb_core(O) rc_core(O) 
videobuf2_memops(O) videobuf2_v4l2(O) videobuf2_core(O) videodev(O) media(O) 
bluetooth ecdh_generic ums_realtek uas rtl8192cu rtl_usb rtl8192c_common 
rtlwifi usb_storage snd_hda_codec_realtek snd_hda_codec_hdmi 
snd_hda_codec_generic i2c_mux snd_hda_intel snd_hda_codec snd_hwdep 
x86_pkg_temp_thermal snd_hda_core kvm_intel kvm irqbypass [last unloaded: 
videobuf2_memops]
  [ 6058.867497] CPU: 2 PID: 7349 Comm: kworker/2:0 Tainted: GW  O
4.13.9-gentoo #1
  [ 6058.867595] Hardware name: MEDION E2050 2391/H81H3-EM2, BIOS H81EM2W08.308 
08/25/2014
  [ 6058.867692] Workqueue: usb_hub_wq hub_event
  [ 6058.867746] task: 88011a15e040 task.stack: c90003074000
  [ 6058.867825] RIP: 0010:dvb_frontend_stop+0x30/0xd0 [dvb_core]
  [ 6058.867896] RSP: 0018:c90003077b58 EFLAGS: 00010293
  [ 6058.867964] RAX:  RBX:  RCX: 
00010040001f
  [ 6058.868056] RDX: 88011a15e040 RSI: ea000464e400 RDI: 
88001cbe3028
  [ 6058.868150] RBP: c90003077b68 R08: 880119390380 R09: 
00010040001f
  [ 6058.868241] R10: c90003077b18 R11: 0001e200 R12: 
88001cbe3028
  [ 6058.868330] R13: 88001cbe68d0 R14: 8800cf734000 R15: 
8800cf734098
  [ 6058.868419] FS:  () GS:88011fb0() 
knlGS:
  [ 6058.868511] CS:  0010 DS:  ES:  CR0: 80050033
  [ 6058.868578] CR2: 01f8 CR3: 0001113c5000 CR4: 
001406e0
  [ 6058.868662] Call Trace:
  [ 6058.868705]  dvb_unregister_frontend+0x2a/0x80 [dvb_core]
  [ 6058.868774]  em28xx_dvb_fini+0x132/0x220 [em28xx_dvb]
  [ 6058.868840]  em28xx_close_extension+0x34/0x90 [em28xx]
  [ 6058.868902]  em28xx_usb_disconnect+0x4e/0x70 [em28xx]
  [ 6058.868968]  usb_unbind_interface+0x6d/0x260
  [ 6058.869025]  device_release_driver_internal+0x150/0x210
  [ 6058.869094]  device_release_driver+0xd/0x10
  [ 6058.869150]  bus_remove_device+0xe4/0x160
  [ 6058.869204]  device_del+0x1ce/0x2f0
  [ 6058.869253]  usb_disable_device+0x99/0x270
  [ 6058.869306]  usb_disconnect+0x8d/0x260
  [ 6058.869359]  hub_event+0x93d/0x1520
  [ 6058.869408]  ? dequeue_task_fair+0xae5/0xd20
  [ 6058.869467]  process_one_work+0x1d9/0x3e0
  [ 6058.869522]  worker_thread+0x43/0x3e0
  [ 6058.869576]  kthread+0x104/0x140
  [ 6058.869602]  ? trace_event_raw_event_workqueue_work+0x80/0x80
  [ 6058.869640]  ? kthread_create_on_node+0x40/0x40
  [ 6058.869673]  ret_from_fork+0x22/0x30
  [ 6058.869698] Code: 54 49 89 fc 53 48 8b 9f 18 03 00 00 0f 1f 44 00 00 41 83 
bc 24 04 05 00 00 02 74 0c 41 c7 84 24 04 05 00 00 01 00 00 00 0f ae f0 <48> 8b 
bb f8 01 00 00 48 85 ff 74 5c e8 df 40 f0 e0 48 8b 93 f8
  [ 6058.869850] RIP: dvb_frontend_stop+0x30/0xd0 [dvb_core] RSP: 
c90003077b58
  [ 6058.869894] CR2: 01f8
  [ 6058.875880] ---[ end trace 717eecf7193b3fc6 ]---

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/usb/em28xx/em28xx-dvb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c 
b/drivers/media/usb/em28xx/em28xx-dvb.c
index 4a7db623fe29..29cdaaf1ed90 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -2105,6 +2105,8 @@ static int em28xx_dvb_fini(struct em28xx *dev)
}
}
 
+   em28xx_unregister_dvb(dvb);
+
/* remove I2C SEC */
client = dvb->i2c_client_sec;
if (client) {
@@ -2126,7 +2128,6 @@ static int em28xx_dvb_fini(struct em28xx *dev)
i2c_unregister_device(client);
}
 
-   em28xx_unregister_dvb(dvb);
kfree(dvb);
dev->dvb = NULL;
kref_put(>ref, em28xx_free_device);
-- 
2.14.2



[PATCH] __dvb_frontend_free: Clear frontend_priv earlier

2017-10-30 Thread Matthias Schwarzott
sk 24:
 save_stack_trace+0x1b/0x20 arch/x86/kernel/stacktrace.c:59
 save_stack+0x43/0xd0 mm/kasan/kasan.c:447
 set_track mm/kasan/kasan.c:459
 kasan_slab_free+0x72/0xc0 mm/kasan/kasan.c:524
 slab_free_hook mm/slub.c:1390
 slab_free_freelist_hook mm/slub.c:1412
 slab_free mm/slub.c:2988
 kfree+0xf6/0x2f0 mm/slub.c:3919
 dtt200u_fe_release+0x3c/0x50 drivers/media/usb/dvb-usb/dtt200u-fe.c:202
 dvb_frontend_invoke_release.part.13+0x1c/0x30 
drivers/media/dvb-core/dvb_frontend.c:2790
 dvb_frontend_invoke_release drivers/media/dvb-core/dvb_frontend.c:2789
 __dvb_frontend_free+0xad/0x120 drivers/media/dvb-core/dvb_frontend.c:153
 dvb_frontend_put+0x59/0x70 drivers/media/dvb-core/dvb_frontend.c:176
 dvb_frontend_detach+0x120/0x150 drivers/media/dvb-core/dvb_frontend.c:2803
 dvb_usb_adapter_frontend_exit+0xd6/0x160 
drivers/media/usb/dvb-usb/dvb-usb-dvb.c:340
 dvb_usb_adapter_exit drivers/media/usb/dvb-usb/dvb-usb-init.c:116
 dvb_usb_exit+0x9b/0x200 drivers/media/usb/dvb-usb/dvb-usb-init.c:132
 dvb_usb_device_exit+0xa5/0xf0 drivers/media/usb/dvb-usb/dvb-usb-init.c:295
 usb_unbind_interface+0x21c/0xa90 drivers/usb/core/driver.c:423
 __device_release_driver drivers/base/dd.c:861
 device_release_driver_internal+0x4f1/0x5c0 drivers/base/dd.c:893
 device_release_driver+0x1e/0x30 drivers/base/dd.c:918
 bus_remove_device+0x2f4/0x4b0 drivers/base/bus.c:565
 device_del+0x5c4/0xab0 drivers/base/core.c:1985
 usb_disable_device+0x1e9/0x680 drivers/usb/core/message.c:1170
 usb_disconnect+0x260/0x7a0 drivers/usb/core/hub.c:2124
 hub_port_connect drivers/usb/core/hub.c:4754
 hub_port_connect_change drivers/usb/core/hub.c:5009
 port_event drivers/usb/core/hub.c:5115
 hub_event+0x1318/0x3740 drivers/usb/core/hub.c:5195
 process_one_work+0xc73/0x1d90 kernel/workqueue.c:2119
 worker_thread+0x221/0x1850 kernel/workqueue.c:2253
 kthread+0x363/0x440 kernel/kthread.c:231
 ret_from_fork+0x2a/0x40 arch/x86/entry/entry_64.S:431

The buggy address belongs to the object at 880067d45500
 which belongs to the cache kmalloc-2048 of size 2048
The buggy address is located 1280 bytes inside of
 2048-byte region [880067d45500, 880067d45d00)
The buggy address belongs to the page:
page:ea00019f5000 count:1 mapcount:0 mapping:  (null)
index:0x0 compound_mapcount: 0
flags: 0x1008100(slab|head)
raw: 01008100   0001000f000f
raw: dead0100 dead0200 88006c002d80 
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 880067d45900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 880067d45980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> 880067d45a00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
   ^
 880067d45a80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 880067d45b00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==

Fixes: ead666000a5f ("media: dvb_frontend: only use kref after initialized")

Reported-by: Andrey Konovalov <andreyk...@google.com>
Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
Tested-by: Andrey Konovalov <andreyk...@google.com>
---
 drivers/media/dvb-core/dvb_frontend.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index daaf969719e4..f552acdb7d8c 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -150,10 +150,11 @@ static void __dvb_frontend_free(struct dvb_frontend *fe)
 
dvb_free_device(fepriv->dvbdev);
 
+   fe->frontend_priv = NULL;
+
dvb_frontend_invoke_release(fe, fe->ops.release);
 
kfree(fepriv);
-   fe->frontend_priv = NULL;
 }
 
 static void dvb_frontend_free(struct kref *ref)
-- 
2.14.2



Re: usb/media/dtt200u: use-after-free in __dvb_frontend_free

2017-10-23 Thread Matthias Schwarzott
Am 23.10.2017 um 16:41 schrieb Andrey Konovalov:
> Hi!
> 
> I've got the following report while fuzzing the kernel with syzkaller.
> 
> On commit 3e0cc09a3a2c40ec1ffb6b4e12da86e98feccb11 (4.14-rc5+).
> 
> dvb-usb: found a 'WideView WT-220U PenType Receiver (based on ZL353)'
> in warm state.
> dvb-usb: bulk message failed: -22 (2/1102416563)
> dvb-usb: will use the device's hardware PID filter (table count: 15).
> dvbdev: DVB: registering new adapter (WideView WT-220U PenType
> Receiver (based on ZL353))
> usb 1-1: media controller created
> dvbdev: dvb_create_media_entity: media entity 'dvb-demux' registered.
> usb 1-1: DVB: registering adapter 0 frontend 0 (WideView USB DVB-T)...
> dvbdev: dvb_create_media_entity: media entity 'WideView USB DVB-T' registered.
> Registered IR keymap rc-dtt200u
> rc rc1: IR-receiver inside an USB DVB receiver as
> /devices/platform/dummy_hcd.0/usb1/1-1/rc/rc1
> input: IR-receiver inside an USB DVB receiver as
> /devices/platform/dummy_hcd.0/usb1/1-1/rc/rc1/input9
> dvb-usb: schedule remote query interval to 300 msecs.
> dvb-usb: WideView WT-220U PenType Receiver (based on ZL353)
> successfully initialized and connected.
> dvb-usb: bulk message failed: -22 (1/1807119384)
> dvb-usb: error -22 while querying for an remote control event.
> dvb-usb: bulk message failed: -22 (1/1807119384)
> dvb-usb: error -22 while querying for an remote control event.
> dvb-usb: bulk message failed: -22 (1/1807119384)
> dvb-usb: error -22 while querying for an remote control event.
> dvb-usb: bulk message failed: -22 (1/1807119384)
> dvb-usb: error -22 while querying for an remote control event.
> dvb-usb: bulk message failed: -22 (1/1807119384)
> dvb-usb: error -22 while querying for an remote control event.
> dvb-usb: bulk message failed: -22 (1/1807119384)
> dvb-usb: error -22 while querying for an remote control event.
> usb 1-1: USB disconnect, device number 2
> ==
> BUG: KASAN: use-after-free in __dvb_frontend_free+0x113/0x120
> Write of size 8 at addr 880067d45a00 by task kworker/0:1/24
> 
> CPU: 0 PID: 24 Comm: kworker/0:1 Not tainted 4.14.0-rc5-43687-g06ab8a23e0e6 
> #545
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
> Workqueue: usb_hub_wq hub_event
> Call Trace:
>  __dump_stack lib/dump_stack.c:16
>  dump_stack+0x292/0x395 lib/dump_stack.c:52
>  print_address_description+0x78/0x280 mm/kasan/report.c:252
>  kasan_report_error mm/kasan/report.c:351
>  kasan_report+0x23d/0x350 mm/kasan/report.c:409
>  __asan_report_store8_noabort+0x1c/0x20 mm/kasan/report.c:435
>  __dvb_frontend_free+0x113/0x120 drivers/media/dvb-core/dvb_frontend.c:156
>  dvb_frontend_put+0x59/0x70 drivers/media/dvb-core/dvb_frontend.c:176
>  dvb_frontend_detach+0x120/0x150 drivers/media/dvb-core/dvb_frontend.c:2803
>  dvb_usb_adapter_frontend_exit+0xd6/0x160
> drivers/media/usb/dvb-usb/dvb-usb-dvb.c:340
>  dvb_usb_adapter_exit drivers/media/usb/dvb-usb/dvb-usb-init.c:116
>  dvb_usb_exit+0x9b/0x200 drivers/media/usb/dvb-usb/dvb-usb-init.c:132
>  dvb_usb_device_exit+0xa5/0xf0 drivers/media/usb/dvb-usb/dvb-usb-init.c:295
>  usb_unbind_interface+0x21c/0xa90 drivers/usb/core/driver.c:423
>  __device_release_driver drivers/base/dd.c:861
>  device_release_driver_internal+0x4f1/0x5c0 drivers/base/dd.c:893
>  device_release_driver+0x1e/0x30 drivers/base/dd.c:918
>  bus_remove_device+0x2f4/0x4b0 drivers/base/bus.c:565
>  device_del+0x5c4/0xab0 drivers/base/core.c:1985
>  usb_disable_device+0x1e9/0x680 drivers/usb/core/message.c:1170
>  usb_disconnect+0x260/0x7a0 drivers/usb/core/hub.c:2124
>  hub_port_connect drivers/usb/core/hub.c:4754
>  hub_port_connect_change drivers/usb/core/hub.c:5009
>  port_event drivers/usb/core/hub.c:5115
>  hub_event+0x1318/0x3740 drivers/usb/core/hub.c:5195
>  process_one_work+0xc73/0x1d90 kernel/workqueue.c:2119
>  worker_thread+0x221/0x1850 kernel/workqueue.c:2253
>  kthread+0x363/0x440 kernel/kthread.c:231
>  ret_from_fork+0x2a/0x40 arch/x86/entry/entry_64.S:431
> 
It looks like this is caused by commit
ead666000a5fe34bdc82d61838e4df2d416ea15e ("media: dvb_frontend: only use
kref after initialized").

The writing to "fe->frontend_priv" in dvb_frontend.c:156 is a
use-after-free in case the object dvb_frontend *fe is already freed by
the release callback called in line 153.
Only if the demod driver is based on new style i2c_client the memory is
still accessible.

There are two possible solutions:
1. Clear fe->frontend_priv earlier (before line 153).
2. Do not clear fe->frontend_priv

Can you try if the following patch (solution 1) fixes the issue?

Regards
Matthias

diff --git a/drivers/media/dvb-core/dvb_frontend.c
b/drivers/media/dvb-core/dvb_frontend.c
index daaf969719e4..f552acdb7d8c 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -150,10 +150,11 @@ static void __dvb_frontend_free(struct
dvb_frontend *fe)


Re: [PATCH] Simplify major/minor non-dynamic logic

2017-10-15 Thread Matthias Schwarzott
Am 11.10.2017 um 21:36 schrieb Mauro Carvalho Chehab:
> changeset 6bbf7a855d20 ("media: dvbdev: convert DVB device types into an 
> enum")
> added a new warning on gcc 6:
> 
>>> drivers/media/dvb-core/dvbdev.c:86:1: warning: control reaches end of 
>>> non-void function [-Wreturn-type]
> 
> That's because gcc is not smart enough to see that all types are
> present at the switch. Also, the current code is not too optimized.
> 
How should the compiler know that "int type" will only contain values
0..8? dvb_register_adapter is not inlined.

> So, replace it to a more optimized one, based on a static table.
> 
> Reported-by: kbuild test robot 
> Fixes: 6bbf7a855d20 ("media: dvbdev: convert DVB device types into an enum")
> Signed-off-by: Mauro Carvalho Chehab 
> ---
> I actually suggested this patch to be fold with changeset 6bbf7a855d20.
> Unfortunately, I actually forgot to do that (I guess I did, but on a different
> machine than the one I used today to pick it).
> 
> Anyway, that saves some code space with static minors and cleans up
> a warning. So, let's apply it.
> 
>  drivers/media/dvb-core/dvbdev.c | 28 +---
>  1 file changed, 13 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
> index a53eb53a4fd5..060c60ddfcc3 100644
> --- a/drivers/media/dvb-core/dvbdev.c
> +++ b/drivers/media/dvb-core/dvbdev.c
> @@ -68,22 +68,20 @@ static const char * const dnames[] = {
>  #else
>  #define DVB_MAX_IDS  4
>  
> -static int nums2minor(int num, enum dvb_device_type type, int id)
> -{
> - int n = (num << 6) | (id << 4);
> +static const u8 minor_type[] = {
> +   [DVB_DEVICE_VIDEO]  = 0,
> +   [DVB_DEVICE_AUDIO]  = 1,
> +   [DVB_DEVICE_SEC]= 2,
> +   [DVB_DEVICE_FRONTEND]   = 3,
> +   [DVB_DEVICE_DEMUX]  = 4,
> +   [DVB_DEVICE_DVR]= 5,
> +   [DVB_DEVICE_CA] = 6,
> +   [DVB_DEVICE_NET]= 7,
> +   [DVB_DEVICE_OSD]= 8,
> +};
>  
> - switch (type) {
> - case DVB_DEVICE_VIDEO:  return n;
> - case DVB_DEVICE_AUDIO:  return n | 1;
> - case DVB_DEVICE_SEC:return n | 2;
> - case DVB_DEVICE_FRONTEND:   return n | 3;
> - case DVB_DEVICE_DEMUX:  return n | 4;
> - case DVB_DEVICE_DVR:return n | 5;
> - case DVB_DEVICE_CA: return n | 6;
> - case DVB_DEVICE_NET:return n | 7;
> - case DVB_DEVICE_OSD:return n | 8;
> - }
> -}
> +#define nums2minor(num, type, id) \
> +   (((num) << 6) | ((id) << 4) | minor_type[type])

In this code it is problematic that a bad value of type will trigger an
invalid memory access.

>  
>  #define MAX_DVB_MINORS   (DVB_MAX_ADAPTERS*64)
>  #endif
> 

Regards
Matthias


[PATCH] cx23885: Explicitly list Hauppauge model numbers of HVR-4400 and HVR-5500

2017-08-27 Thread Matthias Schwarzott
Add two new model numbers to suppress this message in kernel log:
  cx23885: cx23885[0]: warning: unknown hauppauge model #121029

Add these model numbers:
* Model 121019 - WinTV-HVR4400
* Model 121029 - WinTV-HVR5500

For WinTV-HVR4400 the documentation and my hardware differ:

Documentation says it supports DVB-S/S2 and DVB-T,
but my hardware also supports DVB-C.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/pci/cx23885/cx23885-cards.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/pci/cx23885/cx23885-cards.c 
b/drivers/media/pci/cx23885/cx23885-cards.c
index c48fa8e25a70..78a8836d03e4 100644
--- a/drivers/media/pci/cx23885/cx23885-cards.c
+++ b/drivers/media/pci/cx23885/cx23885-cards.c
@@ -1278,6 +1278,12 @@ static void hauppauge_eeprom(struct cx23885_dev *dev, u8 
*eeprom_data)
case 85721:
/* WinTV-HVR1290 (PCIe, OEM, RCA in, IR,
Dual channel ATSC and Basic analog */
+   case 121019:
+   /* WinTV-HVR4400 (PCIe, DVB-S2, DVB-C/T) */
+   break;
+   case 121029:
+   /* WinTV-HVR5500 (PCIe, DVB-S2, DVB-C/T) */
+   break;
case 150329:
/* WinTV-HVR5525 (PCIe, DVB-S/S2, DVB-T/T2/C) */
break;
-- 
2.14.1



Fwd: Aw: Fwd: [PATCH 1/2] cx23885: Fix use-after-free when unregistering the i2c_client for the dvb demod

2017-08-27 Thread Matthias Schwarzott
Forwarding a tested-by statement (using a HVR-5500).

Regards
Matthias

 Weitergeleitete Nachricht 
Betreff: Aw: Fwd: [PATCH 1/2] cx23885: Fix use-after-free when
unregistering the i2c_client for the dvb demod
Datum: Sun, 27 Aug 2017 12:18:55 +0200
Von: "Sven Müller" <xpert-reac...@gmx.de>
An: Matthias Schwarzott <z...@gentoo.org>

Tested-by: Sven Müller <xpert-reac...@gmx.de>

> Gesendet: Sonntag, 27. August 2017 um 12:12 Uhr
> Von: "Matthias Schwarzott" <z...@gentoo.org>
> An: "Sven Müller" <xpert-reac...@gmx.de>
> Betreff: Fwd: [PATCH 1/2] cx23885: Fix use-after-free when unregistering the 
> i2c_client for the dvb demod
>
> 
> 
> 
>  Weitergeleitete Nachricht 
> Betreff: [PATCH 1/2] cx23885: Fix use-after-free when unregistering the
> i2c_client for the dvb demod
> Datum: Wed,  2 Aug 2017 18:45:59 +0200
> Von: Matthias Schwarzott <z...@gentoo.org>
> An: linux-media@vger.kernel.org
> Kopie (CC): mche...@osg.samsung.com, cr...@iki.fi, Matthias Schwarzott
> <z...@gentoo.org>
> 
> Unregistering the i2c_client of the demod driver destroys the frontend
> object.
> Calling vb2_dvb_unregister_bus later accesses the frontend (and with the
> refcount_t) conversion the refcount_t code complains:
> 
> kernel: [ cut here ]
> kernel: WARNING: CPU: 0 PID: 7883 at lib/refcount.c:128
> refcount_sub_and_test+0x70/0x80
> kernel: refcount_t: underflow; use-after-free.
> kernel: Modules linked in: bluetooth si2165(O) a8293(O) tda10071(O)
> tea5767(O) tuner(O) cx23885(O-) tda18271(O) videobuf2_dvb(O)
> videobuf2_dma_sg(O) m88ds3103(O) tveeprom(O) cx2341x(O) v4l2_common(O)
> dvb_core(O) rc_core(O) videobuf2_memops(O) videobuf2_v4l2(O) ums_realtek
> videobuf2_core(O) uas videodev(O) media(O) rtl8192cu i2c_mux usb_storage
> rtl_usb rtl8192c_common rtlwifi snd_hda_codec_hdmi snd_hda_codec_realtek
> snd_hda_codec_generic snd_hda_intel snd_hda_codec snd_hwdep snd_hda_core
> x86_pkg_temp_thermal kvm_intel kvm irqbypass
> kernel: CPU: 0 PID: 7883 Comm: rmmod Tainted: GW  O
> 4.11.3-gentoo #3
> kernel: Hardware name: MEDION E2050 2391/H81H3-EM2, BIOS H81EM2W08.308
> 08/25/2014
> kernel: Call Trace:
> kernel:  dump_stack+0x4d/0x66
> kernel:  __warn+0xc6/0xe0
> kernel:  warn_slowpath_fmt+0x46/0x50
> kernel:  ? kobject_put+0x2f/0x60
> kernel:  refcount_sub_and_test+0x70/0x80
> kernel:  refcount_dec_and_test+0x11/0x20
> kernel:  dvb_unregister_frontend+0x42/0x60 [dvb_core]
> kernel:  vb2_dvb_dealloc_frontends+0x9e/0x100 [videobuf2_dvb]
> kernel:  vb2_dvb_unregister_bus+0xd/0x20 [videobuf2_dvb]
> kernel:  cx23885_dvb_unregister+0xc3/0x110 [cx23885]
> kernel:  cx23885_dev_unregister+0xea/0x150 [cx23885]
> kernel:  cx23885_finidev+0x4f/0x70 [cx23885]
> kernel:  pci_device_remove+0x34/0xb0
> kernel:  device_release_driver_internal+0x150/0x200
> kernel:  driver_detach+0x33/0x70
> kernel:  bus_remove_driver+0x47/0xa0
> kernel:  driver_unregister+0x27/0x50
> kernel:  pci_unregister_driver+0x34/0x90
> kernel:  cx23885_fini+0x10/0x12 [cx23885]
> kernel:  SyS_delete_module+0x166/0x220
> kernel:  ? exit_to_usermode_loop+0x7b/0x80
> kernel:  entry_SYSCALL_64_fastpath+0x17/0x98
> kernel: RIP: 0033:0x7f5901680b07
> kernel: RSP: 002b:7ffdf6cdb028 EFLAGS: 0206 ORIG_RAX:
> 00b0
> kernel: RAX: ffda RBX: 0003 RCX: 7f5901680b07
> kernel: RDX: 000a RSI: 0800 RDI: 01500258
> kernel: RBP: 015001f0 R08: 0000 R09: 1999
> kernel: R10: 0884 R11: 0206 R12: 7ffdf6cda010
> kernel: R13:  R14: 015001f0 R15: 014ff010
> kernel: ---[ end trace c3a4659b89086061 ]---
> 
> Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
> ---
>  drivers/media/pci/cx23885/cx23885-dvb.c | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c
> b/drivers/media/pci/cx23885/cx23885-dvb.c
> index 979b66627f60..e795ddeb7fe2 100644
> --- a/drivers/media/pci/cx23885/cx23885-dvb.c
> +++ b/drivers/media/pci/cx23885/cx23885-dvb.c
> @@ -2637,6 +2637,11 @@ int cx23885_dvb_unregister(struct cx23885_tsport
> *port)
>   struct vb2_dvb_frontend *fe0;
>   struct i2c_client *client;
>  +fe0 = vb2_dvb_get_frontend(>frontends, 1);
> +
> + if (fe0 && fe0->dvb.frontend)
> + vb2_dvb_unregister_bus(>frontends);
> +
>   /* remove I2C client for CI */
>   client = port->i2c_client_ci;
>   if (client) {
> @@ -2665,11 +2670,6 @@ int cx23885_dvb_unregister(struct cx23885_tsport
> *port)
>   i2c_unregister_device(client);
>   }
>  -fe0 = vb2_dvb_get_frontend(>frontends, 1);
> -
> - if (fe0 && fe0->dvb.frontend)
> - vb2_dvb_unregister_bus(>frontends);
> -
>   switch (port->dev->board) {
>   case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
>   netup_ci_exit(port);
> -- 
> 2.13.3
> 
> 
>



Re: [PATCH 1/2] cx23885: Fix use-after-free when unregistering the i2c_client for the dvb demod

2017-08-23 Thread Matthias Schwarzott
Am 02.08.2017 um 18:45 schrieb Matthias Schwarzott:
> diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c 
> b/drivers/media/pci/cx23885/cx23885-dvb.c
> index 979b66627f60..e795ddeb7fe2 100644
> --- a/drivers/media/pci/cx23885/cx23885-dvb.c
> +++ b/drivers/media/pci/cx23885/cx23885-dvb.c
> @@ -2637,6 +2637,11 @@ int cx23885_dvb_unregister(struct cx23885_tsport *port)
>   struct vb2_dvb_frontend *fe0;
>   struct i2c_client *client;
>  
> + fe0 = vb2_dvb_get_frontend(>frontends, 1);
> +
> + if (fe0 && fe0->dvb.frontend)
> + vb2_dvb_unregister_bus(>frontends);
> +
>   /* remove I2C client for CI */
>   client = port->i2c_client_ci;
>   if (client) {
> @@ -2665,11 +2670,6 @@ int cx23885_dvb_unregister(struct cx23885_tsport *port)
>   i2c_unregister_device(client);
>   }
>  
> - fe0 = vb2_dvb_get_frontend(>frontends, 1);
> -
> - if (fe0 && fe0->dvb.frontend)
> - vb2_dvb_unregister_bus(>frontends);
> -

The following code is after i2c_unregister_device.
>   switch (port->dev->board) {
>   case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
>   netup_ci_exit(port);
> 
I wonder if the code above should be moved to before the
i2c_unregister_device block.
Currently these NETUP board drivers do not use "new style/i2c_client
based" frontend drivers. But if in future this switch is extended one
could get in trouble.

Regards
Matthias


Re: analog support for WinTV-HVR-900H/930C-HD

2017-08-23 Thread Matthias Schwarzott
Am 19.08.2017 um 21:46 schrieb Sven Verdoolaege:
> Hi,
> 

Hi!

> I hope this is the right place for asking about support
> for analog TV on Hauppauge cards.
> 
> I recently bought what I thought is a Hauppauge WinTV-HVR-900H
> (that's what it says on the stick itself) because according
> to https://www.linuxtv.org/wiki/index.php/Hauppauge_WinTV-HVR-900H
> analog TV should work on those sticks.
> However, the stick is identified as a
> "Hauppauge WinTV 930C-HD (1114xx) / HVR-901H (1114xx) / PCTV QuatroStick 522e"
> instead and it seems that there is no support for analog TV
> for this device (yet?).
> 
> In particular, when I try to run tvtime, I get
> videoinput: Can't get tuner info: Inappropriate ioctl for device
> videoinput: Can't set tuner audio mode: Inappropriate ioctl for device
> videoinput: Can't get tuner info: Inappropriate ioctl for device
> videoinput: Can't set tuner audio mode: Inappropriate ioctl for device
> videoinput: Tuner present, but our request to change to
> videoinput: frequency 62250 failed with this error: Inappropriate ioctl for 
> device.
> videoinput: Please file a bug report at http://tvtime.net/
> videoinput: Tuner refuses to tell us the current frequency: Inappropriate 
> ioctl for device
> videoinput: Please file a bug report at http://tvtime.net/
> 
> Is anyone working on support for such devices?
> Or does it already work and am I doing something wrong?
> 
> I'm pasting the relevant dmesg output below.
> Kernel version is 4.4.0-83-generic #106-Ubuntu.
> 
> Thanks,
> 
> skimo
> 
> [   44.522766] usb 3-4: new high-speed USB device number 2 using xhci_hcd
> [   44.653945] usb 3-4: New USB device found, idVendor=2013, idProduct=025e
> [   44.653947] usb 3-4: New USB device strings: Mfr=1, Product=2, 
> SerialNumber=3
> [   44.653949] usb 3-4: Product: Hauppauge Device
> [   44.653950] usb 3-4: Manufacturer: Hauppauge
> [   44.653951] usb 3-4: SerialNumber: 4035578631
> [   44.698824] Registered IR keymap rc-pinnacle-pctv-hd
> [   44.698928] input: Conexant Hybrid TV (cx231xx) MCE IR no TX (2013:025e) 
> as /devices/pci:00/:00:14.0/usb3/3-4/3-4:1.0/rc/rc0/input23
> [   44.698985] rc0: Conexant Hybrid TV (cx231xx) MCE IR no TX (2013:025e) as 
> /devices/pci:00/:00:14.0/usb3/3-4/3-4:1.0/rc/rc0
> [   44.703474] IR NEC protocol handler initialized
> [   44.703661] IR Sony protocol handler initialized
> [   44.703955] IR JVC protocol handler initialized
> [   44.703958] IR RC6 protocol handler initialized
> [   44.704086] IR SANYO protocol handler initialized
> [   44.704636] IR RC5(x/sz) protocol handler initialized
> [   44.704930] IR Sharp protocol handler initialized
> [   44.705056] input: MCE IR Keyboard/Mouse (mceusb) as 
> /devices/virtual/input/input24
> [   44.705140] IR MCE Keyboard/mouse protocol handler initialized
> [   44.705330] IR XMP protocol handler initialized
> [   44.705705] lirc_dev: IR Remote Control driver registered, major 240 
> [   44.707056] rc rc0: lirc_dev: driver ir-lirc-codec (mceusb) registered at 
> minor = 0
> [   44.707058] IR LIRC bridge handler initialized
> [   44.907035] mceusb 3-4:1.0: Registered Hauppauge Hauppauge Device with mce 
> emulator interface version 1
> [   44.907038] mceusb 3-4:1.0: 2 tx ports (0x3 cabled) and 2 rx sensors (0x1 
> active)
> [   44.907130] usbcore: registered new interface driver mceusb
> [   44.918365] cx231xx 3-4:1.1: New device Hauppauge Hauppauge Device @ 480 
> Mbps (2013:025e) with 7 interfaces
> [   44.918441] cx231xx 3-4:1.1: Identified as Hauppauge WinTV 930C-HD 
> (1114xx) / HVR-901H (1114xx) / PCTV QuatroStick 522e (card=20)
> [   44.918733] i2c i2c-12: Added multiplexed i2c bus 14
> [   44.918775] i2c i2c-12: Added multiplexed i2c bus 15
> [   45.062403] cx25840 11-0044: cx23102 A/V decoder found @ 0x88 (cx231xx 
> #0-0)
> [   47.044238] cx25840 11-0044: loaded v4l-cx231xx-avcore-01.fw firmware 
> (16382 bytes)
> [   47.101579] tveeprom 14-0050: Hauppauge model 111429, rev E2I6, serial# 
> 4035578631
> [   47.101582] tveeprom 14-0050: MAC address is 00:0d:fe:8a:0b:07
> [   47.101583] tveeprom 14-0050: tuner model is SiLabs Si2157 (idx 186, type 
> 4)
> [   47.101584] tveeprom 14-0050: TV standards PAL(B/G) PAL(I) SECAM(L/L') 
> PAL(D/D1/K) ATSC/DVB Digital (eeprom 0xf4)
> [   47.101585] tveeprom 14-0050: audio processor is CX23102 (idx 47)
> [   47.101586] tveeprom 14-0050: decoder processor is CX23102 (idx 46)
> [   47.101587] tveeprom 14-0050: has radio, has IR receiver, has no IR 
> transmitter
> [   47.102572] cx231xx 3-4:1.1: v4l2 driver version 0.0.3
> [   47.157788] cx231xx 3-4:1.1: Unknown tuner type configuring SIF
> [   47.182657] cx231xx 3-4:1.1: Registered video device video1 [v4l2]
> [   47.182721] cx231xx 3-4:1.1: Registered VBI device vbi0
> [   47.182725] cx231xx 3-4:1.1: video EndPoint Addr 0x84, Alternate settings: 
> 5
> [   47.182728] cx231xx 3-4:1.1: VBI EndPoint Addr 0x85, Alternate settings: 2
> [   47.182730] cx231xx 3-4:1.1: sliced CC EndPoint Addr 0x86, 

[PATCH 2/2] cx231xx: fix use-after-free when unregistering the i2c_client for the dvb demod

2017-08-02 Thread Matthias Schwarzott
Calling i2c_unregister_device for a demod driver destroys the frontend object.
Later it is accessed by calling dvb_unregister_frontend and
dvb_frontend_detach.

In some cases this leads to a general protection fault with this
callstack:

  dvb_unregister_frontend+0x25/0x50 [dvb_core]
  dvb_fini+0xdb/0x160 [cx231xx_dvb]
  cx231xx_unregister_extension+0x3d/0xb0 [cx231xx]
  cx231xx_dvb_unregister+0x10/0x809 [cx231xx_dvb]
  SyS_delete_module+0x18a/0x240
  ? exit_to_usermode_loop+0x7b/0x80
  entry_SYSCALL_64_fastpath+0x17/0x98

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/usb/cx231xx/cx231xx-dvb.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c 
b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index ee3eeeb600f8..c18bb33e060e 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -585,6 +585,9 @@ static void unregister_dvb(struct cx231xx_dvb *dvb)
dvb->demux.dmx.remove_frontend(>demux.dmx, >fe_hw);
dvb_dmxdev_release(>dmxdev);
dvb_dmx_release(>demux);
+   dvb_unregister_frontend(dvb->frontend);
+   dvb_frontend_detach(dvb->frontend);
+   dvb_unregister_adapter(>adapter);
/* remove I2C tuner */
client = dvb->i2c_client_tuner;
if (client) {
@@ -597,9 +600,6 @@ static void unregister_dvb(struct cx231xx_dvb *dvb)
module_put(client->dev.driver->owner);
i2c_unregister_device(client);
}
-   dvb_unregister_frontend(dvb->frontend);
-   dvb_frontend_detach(dvb->frontend);
-   dvb_unregister_adapter(>adapter);
 }
 
 static int dvb_init(struct cx231xx *dev)
-- 
2.13.3



[PATCH 0/2] Fix use-after-free errors when unregistering the i2c_client for the dvb demod

2017-08-02 Thread Matthias Schwarzott
Hi!

There seem to be a general error in a lot of dvb bride drivers about the order 
of i2c_unregister_device
and the calls to dvb_unregister_frontend and dvb_frontend_detach.

As soon as the i2c_client for a demod driver is unregistered the memory for the 
frontend is kfreed.
But the calls to dvb_unregister_frontend and dvb_frontend_detach access it 
later.

I fixed the error in cx23885 and cx231xx driver as I have access to the 
hardware.

Further drivers that might show the same bug (but I cannot test):
* em28xx
* ddbride
* saa7164

Regards
Matthias



[PATCH 1/2] cx23885: Fix use-after-free when unregistering the i2c_client for the dvb demod

2017-08-02 Thread Matthias Schwarzott
Unregistering the i2c_client of the demod driver destroys the frontend
object.
Calling vb2_dvb_unregister_bus later accesses the frontend (and with the
refcount_t) conversion the refcount_t code complains:

kernel: [ cut here ]
kernel: WARNING: CPU: 0 PID: 7883 at lib/refcount.c:128 
refcount_sub_and_test+0x70/0x80
kernel: refcount_t: underflow; use-after-free.
kernel: Modules linked in: bluetooth si2165(O) a8293(O) tda10071(O) tea5767(O) 
tuner(O) cx23885(O-) tda18271(O) videobuf2_dvb(O) videobuf2_dma_sg(O) 
m88ds3103(O) tveeprom(O) cx2341x(O) v4l2_common(O) dvb_core(O) rc_core(O) 
videobuf2_memops(O) videobuf2_v4l2(O) ums_realtek videobuf2_core(O) uas 
videodev(O) media(O) rtl8192cu i2c_mux usb_storage rtl_usb rtl8192c_common 
rtlwifi snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic 
snd_hda_intel snd_hda_codec snd_hwdep snd_hda_core x86_pkg_temp_thermal 
kvm_intel kvm irqbypass
kernel: CPU: 0 PID: 7883 Comm: rmmod Tainted: GW  O4.11.3-gentoo #3
kernel: Hardware name: MEDION E2050 2391/H81H3-EM2, BIOS H81EM2W08.308 
08/25/2014
kernel: Call Trace:
kernel:  dump_stack+0x4d/0x66
kernel:  __warn+0xc6/0xe0
kernel:  warn_slowpath_fmt+0x46/0x50
kernel:  ? kobject_put+0x2f/0x60
kernel:  refcount_sub_and_test+0x70/0x80
kernel:  refcount_dec_and_test+0x11/0x20
kernel:  dvb_unregister_frontend+0x42/0x60 [dvb_core]
kernel:  vb2_dvb_dealloc_frontends+0x9e/0x100 [videobuf2_dvb]
kernel:  vb2_dvb_unregister_bus+0xd/0x20 [videobuf2_dvb]
kernel:  cx23885_dvb_unregister+0xc3/0x110 [cx23885]
kernel:  cx23885_dev_unregister+0xea/0x150 [cx23885]
kernel:  cx23885_finidev+0x4f/0x70 [cx23885]
kernel:  pci_device_remove+0x34/0xb0
kernel:  device_release_driver_internal+0x150/0x200
kernel:  driver_detach+0x33/0x70
kernel:  bus_remove_driver+0x47/0xa0
kernel:  driver_unregister+0x27/0x50
kernel:  pci_unregister_driver+0x34/0x90
kernel:  cx23885_fini+0x10/0x12 [cx23885]
kernel:  SyS_delete_module+0x166/0x220
kernel:  ? exit_to_usermode_loop+0x7b/0x80
kernel:  entry_SYSCALL_64_fastpath+0x17/0x98
kernel: RIP: 0033:0x7f5901680b07
kernel: RSP: 002b:7ffdf6cdb028 EFLAGS: 0206 ORIG_RAX: 00b0
kernel: RAX: ffda RBX: 0003 RCX: 7f5901680b07
kernel: RDX: 000a RSI: 0800 RDI: 01500258
kernel: RBP: 015001f0 R08:  R09: 1999
kernel: R10: 0884 R11: 0206 R12: 7ffdf6cda010
kernel: R13:  R14: 015001f0 R15: 014ff010
kernel: ---[ end trace c3a4659b89086061 ]---

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/pci/cx23885/cx23885-dvb.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c 
b/drivers/media/pci/cx23885/cx23885-dvb.c
index 979b66627f60..e795ddeb7fe2 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -2637,6 +2637,11 @@ int cx23885_dvb_unregister(struct cx23885_tsport *port)
struct vb2_dvb_frontend *fe0;
struct i2c_client *client;
 
+   fe0 = vb2_dvb_get_frontend(>frontends, 1);
+
+   if (fe0 && fe0->dvb.frontend)
+   vb2_dvb_unregister_bus(>frontends);
+
/* remove I2C client for CI */
client = port->i2c_client_ci;
if (client) {
@@ -2665,11 +2670,6 @@ int cx23885_dvb_unregister(struct cx23885_tsport *port)
i2c_unregister_device(client);
}
 
-   fe0 = vb2_dvb_get_frontend(>frontends, 1);
-
-   if (fe0 && fe0->dvb.frontend)
-   vb2_dvb_unregister_bus(>frontends);
-
switch (port->dev->board) {
case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
netup_ci_exit(port);
-- 
2.13.3



[PATCH] Add compat code for skb_put_data

2017-07-23 Thread Matthias Schwarzott
Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 v4l/compat.h  | 12 
 v4l/scripts/make_config_compat.pl |  1 +
 2 files changed, 13 insertions(+)

diff --git a/v4l/compat.h b/v4l/compat.h
index 47e2694..e565292 100644
--- a/v4l/compat.h
+++ b/v4l/compat.h
@@ -2072,4 +2072,16 @@ static inline bool is_of_node(struct fwnode_handle 
*fwnode)
 }
 #endif
 
+#ifdef NEED_SKB_PUT_DATA
+static inline void *skb_put_data(struct sk_buff *skb, const void *data,
+ unsigned int len)
+{
+void *tmp = skb_put(skb, len);
+
+memcpy(tmp, data, len);
+
+return tmp;
+}
+#endif
+
 #endif /*  _COMPAT_H */
diff --git a/v4l/scripts/make_config_compat.pl 
b/v4l/scripts/make_config_compat.pl
index d186cb4..5ac59ab 100644
--- a/v4l/scripts/make_config_compat.pl
+++ b/v4l/scripts/make_config_compat.pl
@@ -699,6 +699,7 @@ sub check_other_dependencies()
check_files_for_func("of_fwnode_handle", "NEED_FWNODE", 
"include/linux/of.h");
check_files_for_func("to_of_node", "NEED_TO_OF_NODE", 
"include/linux/of.h");
check_files_for_func("is_of_node", "NEED_IS_OF_NODE", 
"include/linux/of.h");
+   check_files_for_func("skb_put_data", "NEED_SKB_PUT_DATA", 
"include/linux/skbuff.h");
 
# For tests for uapi-dependent logic
check_files_for_func_uapi("usb_endpoint_maxp", 
"NEED_USB_ENDPOINT_MAXP", "usb/ch9.h");
-- 
2.13.3



Re: Unknown symbol put_vaddr_frames when using media_build

2017-06-07 Thread Matthias Schwarzott
Am 07.06.2017 um 20:23 schrieb Mauro Carvalho Chehab:
> Em Tue, 9 May 2017 06:56:25 +0200
> Matthias Schwarzott <z...@gentoo.org> escreveu:
> 
>> Hi!
>>
>> Whenever I compile the media drivers using media_build against a recent
>> kernel, I get this message when loading them:
>>
>> [5.848537] media: Linux media interface: v0.10
>> [5.881440] Linux video capture interface: v2.00
>> [5.881441] WARNING: You are using an experimental version of the
>> media stack.
>> ...
>> [6.166390] videobuf2_memops: Unknown symbol put_vaddr_frames (err 0)
>> [6.166394] videobuf2_memops: Unknown symbol get_vaddr_frames (err 0)
>> [6.166396] videobuf2_memops: Unknown symbol frame_vector_destroy (err 0)
>> [6.166398] videobuf2_memops: Unknown symbol frame_vector_create (err 0)
>>
>> That means I am not able to load any drivers being based on
>> videobuf2_memops without manual actions.
>>
>> I used kernel 4.11.0, but it does not matter which kernel version
>> exactly is used.
>>
>> My solution for that has been to modify mm/Kconfig of my kernel like
>> this and then enable FRAME_VECTOR in .config
> 
> Well, if you build your Kernel with VB2 compiled, you'll have it.
> 
Sure.

So my question is:
How good do the kernel origin vb2 and the media_build vb2 play together?

Will modprobe always choose the media_build one?
Or will "make install" just overwrite the original file?

>> diff --git a/mm/Kconfig b/mm/Kconfig
>> index 9b8fccb969dc..cfa6a80d1a0a 100644
>> --- a/mm/Kconfig
>> +++ b/mm/Kconfig
>> @@ -701,7 +701,7 @@ config ZONE_DEVICE
>>   If FS_DAX is enabled, then say Y.
>>
>>  config FRAME_VECTOR
>> -   bool
>> +   tristate "frame vector"
>>
>>  config ARCH_USES_HIGH_VMA_FLAGS
>> bool
>>
>> But I do not like that solution.
>> I would prefer one of these solutions:
>>
>> 1. Have media_build apply its fallback the same way as for older kernels
>> that do not even have the the FRAME_VECTOR support.
>>
>> 2. Get the above patch merged (plus description etc.).
>>
>> What do you think?
> 
> (1) is probably simpler, but you would need to play with the building
> system in order to identify if the current Kernel has it enabled or not.
> That could be tricky.
> 
> I suspect people won't accept (2), as it doesn't make sense upstream.

Well, it would be equivalent to options like CRC16 in folder lib.

Regards
Matthias


Unknown symbol put_vaddr_frames when using media_build

2017-05-08 Thread Matthias Schwarzott
Hi!

Whenever I compile the media drivers using media_build against a recent
kernel, I get this message when loading them:

[5.848537] media: Linux media interface: v0.10
[5.881440] Linux video capture interface: v2.00
[5.881441] WARNING: You are using an experimental version of the
media stack.
...
[6.166390] videobuf2_memops: Unknown symbol put_vaddr_frames (err 0)
[6.166394] videobuf2_memops: Unknown symbol get_vaddr_frames (err 0)
[6.166396] videobuf2_memops: Unknown symbol frame_vector_destroy (err 0)
[6.166398] videobuf2_memops: Unknown symbol frame_vector_create (err 0)

That means I am not able to load any drivers being based on
videobuf2_memops without manual actions.

I used kernel 4.11.0, but it does not matter which kernel version
exactly is used.

My solution for that has been to modify mm/Kconfig of my kernel like
this and then enable FRAME_VECTOR in .config

diff --git a/mm/Kconfig b/mm/Kconfig
index 9b8fccb969dc..cfa6a80d1a0a 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -701,7 +701,7 @@ config ZONE_DEVICE
  If FS_DAX is enabled, then say Y.

 config FRAME_VECTOR
-   bool
+   tristate "frame vector"

 config ARCH_USES_HIGH_VMA_FLAGS
bool

But I do not like that solution.
I would prefer one of these solutions:

1. Have media_build apply its fallback the same way as for older kernels
that do not even have the the FRAME_VECTOR support.

2. Get the above patch merged (plus description etc.).

What do you think?

Regards
Matthias


Re: [PATCH v2 01/12] [media] dvb-frontends/stv0367: add flag to make i2c_gatectrl optional

2017-03-27 Thread Matthias Schwarzott
Am 26.03.2017 um 12:34 schrieb Daniel Scheller:
> Am Sun, 26 Mar 2017 10:03:33 +0200
> schrieb Matthias Schwarzott <z...@gentoo.org>:
> 
>> Am 24.03.2017 um 19:23 schrieb Daniel Scheller:
>>> From: Daniel Scheller <d.schel...@gmx.net>
>>>
>>> Some hardware and bridges (namely ddbridge) require that tuner
>>> access is limited to one concurrent access and wrap i2c gate
>>> control with a mutex_lock when attaching frontends. According to
>>> vendor information, this is required as concurrent tuner
>>> reconfiguration can interfere each other and at worst cause tuning
>>> fails or bad reception quality.
>>>
>>> If the demod driver does gate_ctrl before setting up tuner
>>> parameters, and the tuner does another I2C enable, it will deadlock
>>> forever when gate_ctrl is wrapped into the mutex_lock. This adds a
>>> flag and a conditional before triggering gate_ctrl in the
>>> demodulator driver. 
>>
>> If I get this right, the complete call to i2c_gate_ctrl should be
>> disabled. Why not just overwrite the function-pointer i2c_gate_ctrl
>> with NULL in the relevant attach function (stv0367ddb_attach) or not
>> define it in stv0367ddb_ops?
> 
> This will make communication with the TDA18212 tuner chip impossible.
> We need to open stv0367's I2C gate, thus need the function. But for the
> overall hardware case, concurrent tuner reconfiguration must be avoided
> due to the mentioned issues, thus after _attach the bridge driver
> remaps the function pointer to wrap i2c_gate_ctrl with a lock to
> accomplish this - see [1] and [2]. As the demod AND the tuner driver
> both open the I2C gate, this will lead to a dead lock. To not change or
> break existing behaviour with other cards and tuner drivers, this
> (flag, conditional) appears to be the best option.

Ok, I understand: The real problem is that both demod driver (around
tuner access) and tuner driver care about the i2c_gate.

Regards
Matthias



Re: [PATCH v2 01/12] [media] dvb-frontends/stv0367: add flag to make i2c_gatectrl optional

2017-03-26 Thread Matthias Schwarzott
Am 24.03.2017 um 19:23 schrieb Daniel Scheller:
> From: Daniel Scheller 
> 
> Some hardware and bridges (namely ddbridge) require that tuner access is
> limited to one concurrent access and wrap i2c gate control with a
> mutex_lock when attaching frontends. According to vendor information, this
> is required as concurrent tuner reconfiguration can interfere each other
> and at worst cause tuning fails or bad reception quality.
> 
> If the demod driver does gate_ctrl before setting up tuner parameters, and
> the tuner does another I2C enable, it will deadlock forever when gate_ctrl
> is wrapped into the mutex_lock. This adds a flag and a conditional before
> triggering gate_ctrl in the demodulator driver.
> 

If I get this right, the complete call to i2c_gate_ctrl should be disabled.
Why not just overwrite the function-pointer i2c_gate_ctrl with NULL in
the relevant attach function (stv0367ddb_attach) or not define it in
stv0367ddb_ops?

That should have exactly the same effect.

Regards
Matthias



media_build handles FRAME_VECTOR incorrect

2017-02-05 Thread Matthias Schwarzott
Hi!

Compiling the media drivers out of tree with media_build does not handle
FRAME_VECTOR correctly.

My kernel sources have FRAME_VECTOR but it is not enabled. So all
modules depending on it (e.g. VIDEOBUF2_MEMOPS) will fail to load
because the relevant functions cannot be found.

I see two options:
1. Modify the real kernel sources to allow FRAME_VECTOR be enabled via
config (either y or m).

I locally just modified my kernel's mm/KConfig like this:

 config FRAME_VECTOR
-bool
+tristate "enable frame_vector for external modules"

2. Change media_build to supply a replacement when it is not enabled in
the system kernel.

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


[PATCH 3/7] cx231xx: Prepare for attaching new style i2c_client DVB demod drivers

2016-07-26 Thread Matthias Schwarzott
cx231xx does not yet support attaching new-style i2c_client DVB demod
drivers. Add necessary code base on tuner support for i2c_client.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/usb/cx231xx/cx231xx-dvb.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c 
b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index ab2fb9f..f030345 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -65,6 +65,7 @@ struct cx231xx_dvb {
struct dmx_frontend fe_hw;
struct dmx_frontend fe_mem;
struct dvb_net net;
+   struct i2c_client *i2c_client_demod;
struct i2c_client *i2c_client_tuner;
 };
 
@@ -586,8 +587,14 @@ static void unregister_dvb(struct cx231xx_dvb *dvb)
dvb->demux.dmx.remove_frontend(>demux.dmx, >fe_hw);
dvb_dmxdev_release(>dmxdev);
dvb_dmx_release(>demux);
-   client = dvb->i2c_client_tuner;
/* remove I2C tuner */
+   client = dvb->i2c_client_tuner;
+   if (client) {
+   module_put(client->dev.driver->owner);
+   i2c_unregister_device(client);
+   }
+   /* remove I2C demod */
+   client = dvb->i2c_client_demod;
if (client) {
module_put(client->dev.driver->owner);
i2c_unregister_device(client);
-- 
2.9.2

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


[PATCH 7/7] si2165: switch to regmap

2016-07-26 Thread Matthias Schwarzott
This avoids some low-level operations.
It has the benefit that now register values van be read from 
/sys/kernel/debug/regmap
The maximum register value is just a guess - all higher addresses read as zero.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/Kconfig  |  1 +
 drivers/media/dvb-frontends/si2165.c | 70 +---
 2 files changed, 25 insertions(+), 46 deletions(-)

diff --git a/drivers/media/dvb-frontends/Kconfig 
b/drivers/media/dvb-frontends/Kconfig
index c645aa8..8272c08 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -67,6 +67,7 @@ config DVB_TDA18271C2DD
 config DVB_SI2165
tristate "Silicon Labs si2165 based"
depends on DVB_CORE && I2C
+   select REGMAP_I2C
default m if !MEDIA_SUBDRV_AUTOSELECT
help
  A DVB-C/T demodulator.
diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 9bf6609..d63cd73 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "dvb_frontend.h"
 #include "dvb_math.h"
@@ -42,7 +43,7 @@
 struct si2165_state {
struct i2c_client *client;
 
-   struct i2c_adapter *i2c;
+   struct regmap *regmap;
 
struct dvb_frontend fe;
 
@@ -110,61 +111,27 @@ static int si2165_write(struct si2165_state *state, const 
u16 reg,
   const u8 *src, const int count)
 {
int ret;
-   struct i2c_msg msg;
-   u8 buf[2 + 4]; /* write a maximum of 4 bytes of data */
-
-   if (count + 2 > sizeof(buf)) {
-   dev_warn(>client->dev,
- "%s: i2c wr reg=%04x: count=%d is too big!\n",
- KBUILD_MODNAME, reg, count);
-   return -EINVAL;
-   }
-   buf[0] = reg >> 8;
-   buf[1] = reg & 0xff;
-   memcpy(buf + 2, src, count);
-
-   msg.addr = state->config.i2c_addr;
-   msg.flags = 0;
-   msg.buf = buf;
-   msg.len = count + 2;
 
if (debug & DEBUG_I2C_WRITE)
deb_i2c_write("reg: 0x%04x, data: %*ph\n", reg, count, src);
 
-   ret = i2c_transfer(state->i2c, , 1);
+   ret = regmap_bulk_write(state->regmap, reg, src, count);
 
-   if (ret != 1) {
+   if (ret)
dev_err(>client->dev, "%s: ret == %d\n", __func__, ret);
-   if (ret < 0)
-   return ret;
-   else
-   return -EREMOTEIO;
-   }
 
-   return 0;
+   return ret;
 }
 
 static int si2165_read(struct si2165_state *state,
   const u16 reg, u8 *val, const int count)
 {
-   int ret;
-   u8 reg_buf[] = { reg >> 8, reg & 0xff };
-   struct i2c_msg msg[] = {
-   { .addr = state->config.i2c_addr,
- .flags = 0, .buf = reg_buf, .len = 2 },
-   { .addr = state->config.i2c_addr,
- .flags = I2C_M_RD, .buf = val, .len = count },
-   };
+   int ret = regmap_bulk_read(state->regmap, reg, val, count);
 
-   ret = i2c_transfer(state->i2c, msg, 2);
-
-   if (ret != 2) {
+   if (ret) {
dev_err(>client->dev, "%s: error (addr %02x reg %04x 
error (ret == %i)\n",
__func__, state->config.i2c_addr, reg, ret);
-   if (ret < 0)
-   return ret;
-   else
-   return -EREMOTEIO;
+   return ret;
}
 
if (debug & DEBUG_I2C_READ)
@@ -176,9 +143,9 @@ static int si2165_read(struct si2165_state *state,
 static int si2165_readreg8(struct si2165_state *state,
   const u16 reg, u8 *val)
 {
-   int ret;
-
-   ret = si2165_read(state, reg, val, 1);
+   unsigned int val_tmp;
+   int ret = regmap_read(state->regmap, reg, _tmp);
+   *val = (u8)val_tmp;
deb_readreg("R(0x%04x)=0x%02x\n", reg, *val);
return ret;
 }
@@ -196,7 +163,7 @@ static int si2165_readreg16(struct si2165_state *state,
 
 static int si2165_writereg8(struct si2165_state *state, const u16 reg, u8 val)
 {
-   return si2165_write(state, reg, , 1);
+   return regmap_write(state->regmap, reg, val);
 }
 
 static int si2165_writereg16(struct si2165_state *state, const u16 reg, u16 
val)
@@ -1052,6 +1019,11 @@ static int si2165_probe(struct i2c_client *client,
u8 val;
char rev_char;
const char *chip_name;
+   static const struct regmap_config regmap_config = {
+   .reg_bits = 16,
+   .val_bits = 8,
+   .max_register = 0x08ff,
+   };
 
/* allocate memory for the internal state */
state = kzalloc(s

[PATCH 4/7] cx231xx: attach si2165 driver via i2c_client

2016-07-26 Thread Matthias Schwarzott
Use new style attach.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/usb/cx231xx/cx231xx-dvb.c | 73 ++---
 1 file changed, 48 insertions(+), 25 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c 
b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index f030345..1417515 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -151,18 +151,6 @@ static struct tda18271_config pv_tda18271_config = {
.small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
 };
 
-static const struct si2165_config hauppauge_930C_HD_1113xx_si2165_config = {
-   .i2c_addr   = 0x64,
-   .chip_mode  = SI2165_MODE_PLL_XTAL,
-   .ref_freq_Hz= 1600,
-};
-
-static const struct si2165_config pctv_quatro_stick_1114xx_si2165_config = {
-   .i2c_addr   = 0x64,
-   .chip_mode  = SI2165_MODE_PLL_EXT,
-   .ref_freq_Hz= 2400,
-};
-
 static struct lgdt3306a_config hauppauge_955q_lgdt3306a_config = {
.i2c_addr   = 0x59,
.qam_if_khz = 4000,
@@ -756,19 +744,38 @@ static int dvb_init(struct cx231xx *dev)
break;
 
case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx:
+   {
+   struct i2c_client *client;
+   struct i2c_board_info info;
+   struct si2165_platform_data si2165_pdata;
 
-   dev->dvb->frontend = dvb_attach(si2165_attach,
-   _930C_HD_1113xx_si2165_config,
-   demod_i2c
-   );
+   /* attach demod */
+   memset(_pdata, 0, sizeof(si2165_pdata));
+   si2165_pdata.fe = >dvb->frontend;
+   si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL,
+   si2165_pdata.ref_freq_Hz = 1600,
 
-   if (dev->dvb->frontend == NULL) {
+   memset(, 0, sizeof(struct i2c_board_info));
+   strlcpy(info.type, "si2165", I2C_NAME_SIZE);
+   info.addr = 0x64;
+   info.platform_data = _pdata;
+   request_module(info.type);
+   client = i2c_new_device(demod_i2c, );
+   if (client == NULL || client->dev.driver == NULL || 
dev->dvb->frontend == NULL) {
dev_err(dev->dev,
"Failed to attach SI2165 front end\n");
result = -EINVAL;
goto out_free;
}
 
+   if (!try_module_get(client->dev.driver->owner)) {
+   i2c_unregister_device(client);
+   result = -ENODEV;
+   goto out_free;
+   }
+
+   dvb->i2c_client_demod = client;
+
dev->dvb->frontend->ops.i2c_gate_ctrl = NULL;
 
/* define general-purpose callback pointer */
@@ -781,27 +788,43 @@ static int dvb_init(struct cx231xx *dev)
 
dev->cx231xx_reset_analog_tuner = NULL;
break;
-
+   }
case CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx:
{
struct i2c_client *client;
struct i2c_board_info info;
+   struct si2165_platform_data si2165_pdata;
struct si2157_config si2157_config;
 
-   memset(, 0, sizeof(struct i2c_board_info));
+   /* attach demod */
+   memset(_pdata, 0, sizeof(si2165_pdata));
+   si2165_pdata.fe = >dvb->frontend;
+   si2165_pdata.chip_mode = SI2165_MODE_PLL_EXT,
+   si2165_pdata.ref_freq_Hz = 2400,
 
-   dev->dvb->frontend = dvb_attach(si2165_attach,
-   _quatro_stick_1114xx_si2165_config,
-   demod_i2c
-   );
-
-   if (dev->dvb->frontend == NULL) {
+   memset(, 0, sizeof(struct i2c_board_info));
+   strlcpy(info.type, "si2165", I2C_NAME_SIZE);
+   info.addr = 0x64;
+   info.platform_data = _pdata;
+   request_module(info.type);
+   client = i2c_new_device(demod_i2c, );
+   if (client == NULL || client->dev.driver == NULL || 
dev->dvb->frontend == NULL) {
dev_err(dev->dev,
"Failed to attach SI2165 front end\n");
result = -EINVAL;
goto out_free;
}
 
+   if (!try_module_get(client->dev.driver->owner)) {
+   i2c_unregister_device(client);
+   result = -ENODEV;
+   goto out_free;
+   }
+
+   dvb->i2c_client_demod = client;
+
+   memset(, 0, sizeof(struct i2c_board_info));
+
dev->dvb->frontend->ops

[PATCH 2/7] cx23885: attach si2165 driver via i2c_client

2016-07-26 Thread Matthias Schwarzott
Use new style attach.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/pci/cx23885/cx23885-dvb.c | 30 +-
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c 
b/drivers/media/pci/cx23885/cx23885-dvb.c
index e5748a9..5d0bbe4 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -867,12 +867,6 @@ static const struct tda10071_platform_data 
hauppauge_tda10071_pdata = {
.tuner_i2c_addr = 0x54,
 };
 
-static const struct si2165_config hauppauge_hvr4400_si2165_config = {
-   .i2c_addr   = 0x64,
-   .chip_mode  = SI2165_MODE_PLL_XTAL,
-   .ref_freq_Hz= 1600,
-};
-
 static const struct m88ds3103_config dvbsky_t9580_m88ds3103_config = {
.i2c_addr = 0x68,
.clock = 2700,
@@ -1182,6 +1176,7 @@ static int dvb_register(struct cx23885_tsport *port)
struct cx23885_i2c *i2c_bus = NULL, *i2c_bus2 = NULL;
struct vb2_dvb_frontend *fe0, *fe1 = NULL;
struct si2168_config si2168_config;
+   struct si2165_platform_data si2165_pdata;
struct si2157_config si2157_config;
struct ts2020_config ts2020_config;
struct i2c_board_info info;
@@ -1839,9 +1834,26 @@ static int dvb_register(struct cx23885_tsport *port)
break;
/* port c */
case 2:
-   fe0->dvb.frontend = dvb_attach(si2165_attach,
-   _hvr4400_si2165_config,
-   _bus->i2c_adap);
+   /* attach frontend */
+   memset(_pdata, 0, sizeof(si2165_pdata));
+   si2165_pdata.fe = >dvb.frontend;
+   si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL,
+   si2165_pdata.ref_freq_Hz = 1600,
+   memset(, 0, sizeof(struct i2c_board_info));
+   strlcpy(info.type, "si2165", I2C_NAME_SIZE);
+   info.addr = 0x64;
+   info.platform_data = _pdata;
+   request_module(info.type);
+   client_demod = i2c_new_device(_bus->i2c_adap, 
);
+   if (client_demod == NULL ||
+   client_demod->dev.driver == NULL)
+   goto frontend_detach;
+   if (!try_module_get(client_demod->dev.driver->owner)) {
+   i2c_unregister_device(client_demod);
+   goto frontend_detach;
+   }
+   port->i2c_client_demod = client_demod;
+
if (fe0->dvb.frontend == NULL)
break;
fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
-- 
2.9.2

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


[PATCH 6/7] si2165: use i2c_client->dev instead of i2c_adapter->dev for logging

2016-07-26 Thread Matthias Schwarzott
Now that there is a i2c_client, use the more specific dev for logging.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 46 ++--
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index e979fc0..9bf6609 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -114,7 +114,7 @@ static int si2165_write(struct si2165_state *state, const 
u16 reg,
u8 buf[2 + 4]; /* write a maximum of 4 bytes of data */
 
if (count + 2 > sizeof(buf)) {
-   dev_warn(>i2c->dev,
+   dev_warn(>client->dev,
  "%s: i2c wr reg=%04x: count=%d is too big!\n",
  KBUILD_MODNAME, reg, count);
return -EINVAL;
@@ -134,7 +134,7 @@ static int si2165_write(struct si2165_state *state, const 
u16 reg,
ret = i2c_transfer(state->i2c, , 1);
 
if (ret != 1) {
-   dev_err(>i2c->dev, "%s: ret == %d\n", __func__, ret);
+   dev_err(>client->dev, "%s: ret == %d\n", __func__, ret);
if (ret < 0)
return ret;
else
@@ -159,7 +159,7 @@ static int si2165_read(struct si2165_state *state,
ret = i2c_transfer(state->i2c, msg, 2);
 
if (ret != 2) {
-   dev_err(>i2c->dev, "%s: error (addr %02x reg %04x error 
(ret == %i)\n",
+   dev_err(>client->dev, "%s: error (addr %02x reg %04x 
error (ret == %i)\n",
__func__, state->config.i2c_addr, reg, ret);
if (ret < 0)
return ret;
@@ -347,7 +347,7 @@ static int si2165_wait_init_done(struct si2165_state *state)
return 0;
usleep_range(1000, 5);
}
-   dev_err(>i2c->dev, "%s: init_done was not set\n",
+   dev_err(>client->dev, "%s: init_done was not set\n",
KBUILD_MODNAME);
return ret;
 }
@@ -376,14 +376,14 @@ static int si2165_upload_firmware_block(struct 
si2165_state *state,
wordcount = data[offset];
if (wordcount < 1 || data[offset+1] ||
data[offset+2] || data[offset+3]) {
-   dev_warn(>i2c->dev,
+   dev_warn(>client->dev,
 "%s: bad fw data[0..3] = %*ph\n",
KBUILD_MODNAME, 4, data);
return -EINVAL;
}
 
if (offset + 8 + wordcount * 4 > len) {
-   dev_warn(>i2c->dev,
+   dev_warn(>client->dev,
 "%s: len is too small for block len=%d, 
wordcount=%d\n",
KBUILD_MODNAME, len, wordcount);
return -EINVAL;
@@ -446,15 +446,15 @@ static int si2165_upload_firmware(struct si2165_state 
*state)
fw_file = SI2165_FIRMWARE_REV_D;
break;
default:
-   dev_info(>i2c->dev, "%s: no firmware file for 
revision=%d\n",
+   dev_info(>client->dev, "%s: no firmware file for 
revision=%d\n",
KBUILD_MODNAME, state->chip_revcode);
return 0;
}
 
/* request the firmware, this will block and timeout */
-   ret = request_firmware(, fw_file, state->i2c->dev.parent);
+   ret = request_firmware(, fw_file, >client->dev);
if (ret) {
-   dev_warn(>i2c->dev, "%s: firmware file '%s' not found\n",
+   dev_warn(>client->dev, "%s: firmware file '%s' not 
found\n",
KBUILD_MODNAME, fw_file);
goto error;
}
@@ -462,11 +462,11 @@ static int si2165_upload_firmware(struct si2165_state 
*state)
data = fw->data;
len = fw->size;
 
-   dev_info(>i2c->dev, "%s: downloading firmware from file '%s' 
size=%d\n",
+   dev_info(>client->dev, "%s: downloading firmware from file '%s' 
size=%d\n",
KBUILD_MODNAME, fw_file, len);
 
if (len % 4 != 0) {
-   dev_warn(>i2c->dev, "%s: firmware size is not multiple 
of 4\n",
+   dev_warn(>client->dev, "%s: firmware size is not 
multiple of 4\n",
KBUILD_MODNAME);
ret = -EINVAL;
goto error;
@@ -474,14 +474,14 @@ static int si2165_upload_firmware(struct si2165_state 
*state)
 
/* check header (8 bytes) */
if (len < 8) {
-  

[PATCH 5/7] si2165: Remove legacy attach

2016-07-26 Thread Matthias Schwarzott
Now that all users of legacy attach are converted it can be removed.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c  | 117 --
 drivers/media/dvb-frontends/si2165.h  |  31 
 drivers/media/dvb-frontends/si2165_priv.h |  17 +
 3 files changed, 17 insertions(+), 148 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 2d9bbdd..e979fc0 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -1005,14 +1005,6 @@ static int si2165_set_frontend(struct dvb_frontend *fe)
return 0;
 }
 
-static void si2165_release(struct dvb_frontend *fe)
-{
-   struct si2165_state *state = fe->demodulator_priv;
-
-   dprintk("%s: called\n", __func__);
-   kfree(state);
-}
-
 static struct dvb_frontend_ops si2165_ops = {
.info = {
.name = "Silicon Labs ",
@@ -1048,117 +1040,8 @@ static struct dvb_frontend_ops si2165_ops = {
 
.set_frontend  = si2165_set_frontend,
.read_status   = si2165_read_status,
-
-   .release = si2165_release,
 };
 
-struct dvb_frontend *si2165_attach(const struct si2165_config *config,
-  struct i2c_adapter *i2c)
-{
-   struct si2165_state *state = NULL;
-   int n;
-   int io_ret;
-   u8 val;
-   char rev_char;
-   const char *chip_name;
-
-   if (config == NULL || i2c == NULL)
-   goto error;
-
-   /* allocate memory for the internal state */
-   state = kzalloc(sizeof(struct si2165_state), GFP_KERNEL);
-   if (state == NULL)
-   goto error;
-
-   /* setup the state */
-   state->i2c = i2c;
-   state->config = *config;
-
-   if (state->config.ref_freq_Hz < 400
-   || state->config.ref_freq_Hz > 2700) {
-   dev_err(>i2c->dev, "%s: ref_freq of %d Hz not supported 
by this driver\n",
-KBUILD_MODNAME, state->config.ref_freq_Hz);
-   goto error;
-   }
-
-   /* create dvb_frontend */
-   memcpy(>fe.ops, _ops,
-   sizeof(struct dvb_frontend_ops));
-   state->fe.demodulator_priv = state;
-
-   /* powerup */
-   io_ret = si2165_writereg8(state, 0x, state->config.chip_mode);
-   if (io_ret < 0)
-   goto error;
-
-   io_ret = si2165_readreg8(state, 0x, );
-   if (io_ret < 0)
-   goto error;
-   if (val != state->config.chip_mode)
-   goto error;
-
-   io_ret = si2165_readreg8(state, 0x0023, >chip_revcode);
-   if (io_ret < 0)
-   goto error;
-
-   io_ret = si2165_readreg8(state, 0x0118, >chip_type);
-   if (io_ret < 0)
-   goto error;
-
-   /* powerdown */
-   io_ret = si2165_writereg8(state, 0x, SI2165_MODE_OFF);
-   if (io_ret < 0)
-   goto error;
-
-   if (state->chip_revcode < 26)
-   rev_char = 'A' + state->chip_revcode;
-   else
-   rev_char = '?';
-
-   switch (state->chip_type) {
-   case 0x06:
-   chip_name = "Si2161";
-   state->has_dvbt = true;
-   break;
-   case 0x07:
-   chip_name = "Si2165";
-   state->has_dvbt = true;
-   state->has_dvbc = true;
-   break;
-   default:
-   dev_err(>i2c->dev, "%s: Unsupported Silicon Labs chip 
(type %d, rev %d)\n",
-   KBUILD_MODNAME, state->chip_type, state->chip_revcode);
-   goto error;
-   }
-
-   dev_info(>i2c->dev,
-   "%s: Detected Silicon Labs %s-%c (type %d, rev %d)\n",
-   KBUILD_MODNAME, chip_name, rev_char, state->chip_type,
-   state->chip_revcode);
-
-   strlcat(state->fe.ops.info.name, chip_name,
-   sizeof(state->fe.ops.info.name));
-
-   n = 0;
-   if (state->has_dvbt) {
-   state->fe.ops.delsys[n++] = SYS_DVBT;
-   strlcat(state->fe.ops.info.name, " DVB-T",
-   sizeof(state->fe.ops.info.name));
-   }
-   if (state->has_dvbc) {
-   state->fe.ops.delsys[n++] = SYS_DVBC_ANNEX_A;
-   strlcat(state->fe.ops.info.name, " DVB-C",
-   sizeof(state->fe.ops.info.name));
-   }
-
-   return >fe;
-
-error:
-   kfree(state);
-   return NULL;
-}
-EXPORT_SYMBOL(si2165_attach);
-
 static int si2165_probe(struct i2c_client *client,
const struct i2c_device_id *id)
 {
diff --git a/drivers/media/dvb-frontends/si2165.h 
b/drivers/media/dvb-frontends/si2165.h
i

[PATCH 1/7] si2165: support i2c_client attach

2016-07-26 Thread Matthias Schwarzott
Afterwards it is possible to convert attaching in card drivers.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 149 +++
 drivers/media/dvb-frontends/si2165.h |  22 ++
 2 files changed, 171 insertions(+)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 8bf716a..2d9bbdd 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -40,6 +40,8 @@
  */
 
 struct si2165_state {
+   struct i2c_client *client;
+
struct i2c_adapter *i2c;
 
struct dvb_frontend fe;
@@ -1157,6 +1159,153 @@ error:
 }
 EXPORT_SYMBOL(si2165_attach);
 
+static int si2165_probe(struct i2c_client *client,
+   const struct i2c_device_id *id)
+{
+   struct si2165_state *state = NULL;
+   struct si2165_platform_data *pdata = client->dev.platform_data;
+   int n;
+   int ret = 0;
+   u8 val;
+   char rev_char;
+   const char *chip_name;
+
+   /* allocate memory for the internal state */
+   state = kzalloc(sizeof(struct si2165_state), GFP_KERNEL);
+   if (state == NULL) {
+   ret = -ENOMEM;
+   goto error;
+   }
+
+   /* setup the state */
+   state->client = client;
+   state->i2c = client->adapter;
+   state->config.i2c_addr = client->addr;
+   state->config.chip_mode = pdata->chip_mode;
+   state->config.ref_freq_Hz = pdata->ref_freq_Hz;
+   state->config.inversion = pdata->inversion;
+
+   if (state->config.ref_freq_Hz < 400
+   || state->config.ref_freq_Hz > 2700) {
+   dev_err(>i2c->dev, "%s: ref_freq of %d Hz not supported 
by this driver\n",
+KBUILD_MODNAME, state->config.ref_freq_Hz);
+   ret = -EINVAL;
+   goto error;
+   }
+
+   /* create dvb_frontend */
+   memcpy(>fe.ops, _ops,
+   sizeof(struct dvb_frontend_ops));
+   state->fe.ops.release = NULL;
+   state->fe.demodulator_priv = state;
+   i2c_set_clientdata(client, state);
+
+   /* powerup */
+   ret = si2165_writereg8(state, 0x, state->config.chip_mode);
+   if (ret < 0)
+   goto nodev_error;
+
+   ret = si2165_readreg8(state, 0x, );
+   if (ret < 0)
+   goto nodev_error;
+   if (val != state->config.chip_mode)
+   goto nodev_error;
+
+   ret = si2165_readreg8(state, 0x0023, >chip_revcode);
+   if (ret < 0)
+   goto nodev_error;
+
+   ret = si2165_readreg8(state, 0x0118, >chip_type);
+   if (ret < 0)
+   goto nodev_error;
+
+   /* powerdown */
+   ret = si2165_writereg8(state, 0x, SI2165_MODE_OFF);
+   if (ret < 0)
+   goto nodev_error;
+
+   if (state->chip_revcode < 26)
+   rev_char = 'A' + state->chip_revcode;
+   else
+   rev_char = '?';
+
+   switch (state->chip_type) {
+   case 0x06:
+   chip_name = "Si2161";
+   state->has_dvbt = true;
+   break;
+   case 0x07:
+   chip_name = "Si2165";
+   state->has_dvbt = true;
+   state->has_dvbc = true;
+   break;
+   default:
+   dev_err(>i2c->dev, "%s: Unsupported Silicon Labs chip 
(type %d, rev %d)\n",
+   KBUILD_MODNAME, state->chip_type, state->chip_revcode);
+   goto nodev_error;
+   }
+
+   dev_info(>i2c->dev,
+   "%s: Detected Silicon Labs %s-%c (type %d, rev %d)\n",
+   KBUILD_MODNAME, chip_name, rev_char, state->chip_type,
+   state->chip_revcode);
+
+   strlcat(state->fe.ops.info.name, chip_name,
+   sizeof(state->fe.ops.info.name));
+
+   n = 0;
+   if (state->has_dvbt) {
+   state->fe.ops.delsys[n++] = SYS_DVBT;
+   strlcat(state->fe.ops.info.name, " DVB-T",
+   sizeof(state->fe.ops.info.name));
+   }
+   if (state->has_dvbc) {
+   state->fe.ops.delsys[n++] = SYS_DVBC_ANNEX_A;
+   strlcat(state->fe.ops.info.name, " DVB-C",
+   sizeof(state->fe.ops.info.name));
+   }
+
+   /* return fe pointer */
+   *pdata->fe = >fe;
+
+   return 0;
+
+nodev_error:
+   ret = -ENODEV;
+error:
+   kfree(state);
+   dev_dbg(>dev, "failed=%d\n", ret);
+   return ret;
+}
+
+static int si2165_remove(struct i2c_client *client)
+{
+   struct si2165_state *state = i2c_get_clientdata(client);
+
+   dev_dbg(>dev, "\n");
+
+   kfree(state);
+   retu

[PATCH] si2165: avoid division by zero

2016-07-26 Thread Matthias Schwarzott
When si2165_init fails, the clk values in state are still at zero.
But the dvb-core ignores the return value of init will call tune
afterwards.
This will trigger a division by zero when tuning.
At least check for the variables to be non-zero before dividing.

This happened for a system with WinTV HVR-4400 PCIe-card after suspend-to-disk.
Do suspend-to-disk without accessing the DVB device before.
After wakeup try to tune.
si2165_init fails at checking the chip_mode and aborts.
Then si2165_set_if_freq_shift will fail with div-by-zero.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 8bf716a..849c3c4 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -751,6 +751,9 @@ static int si2165_set_oversamp(struct si2165_state *state, 
u32 dvb_rate)
u64 oversamp;
u32 reg_value;
 
+   if (!dvb_rate)
+   return -EINVAL;
+
oversamp = si2165_get_fe_clk(state);
oversamp <<= 23;
do_div(oversamp, dvb_rate);
@@ -775,6 +778,9 @@ static int si2165_set_if_freq_shift(struct si2165_state 
*state)
return -EINVAL;
}
 
+   if (!fe_clk)
+   return -EINVAL;
+
fe->ops.tuner_ops.get_if_frequency(fe, );
if_freq_shift = IF;
if_freq_shift <<= 29;
-- 
2.9.2

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


[REGRESSION/bisected] kernel oops in vb2_core_qbuf when tuning to DVB on the HVR-4400 caused by videobuf2: Refactor vb2_fileio_data and vb2_thread

2016-01-06 Thread Matthias Schwarzott
Hi!

When tuning the HVR-4400 to a DVB-C channel I get this kernel oops:

Jan  3 21:59:39 gauss kernel: BUG: unable to handle kernel NULL pointer
dereference at 01a0
Jan  3 21:59:39 gauss kernel: IP: []
vb2_core_qbuf+0x18/0x200 [videobuf2_core]
Jan  3 21:59:39 gauss kernel: PGD bbf99067 PUD b9dbf067 PMD 0
Jan  3 21:59:39 gauss kernel: Oops:  [#1] SMP
Jan  3 21:59:39 gauss kernel: Modules linked in: si2165(O) a8293(O)
tda10071(O) tea5767(O) tuner(O) cx23885(O) tda18271(O) videobuf2_dvb(O)
videobuf2_dma_sg(O) videobuf2_memops(O) frame_vector(PO)
videobuf2_v4l2(O) videobuf2_core(O) tveeprom(O) cx2341x(O)
v4l2_common(O) videodev(O) media(O) dvb_core(O) rc_core(O) regmap_i2c
bluetooth rtl8192cu rtl_usb rtl8192c_common uas rtlwifi usb_storage
snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic
snd_hda_intel snd_hda_codec x86_pkg_temp_thermal kvm_intel kvm snd_hwdep
snd_hda_core [last unloaded: si2165]
Jan  3 21:59:39 gauss kernel: CPU: 2 PID: 29081 Comm: vb2-cx23885[0]
Tainted: PW  O4.2.8-gentoo #1
Jan  3 21:59:39 gauss kernel: Hardware name: MEDION E2050
2391/H81H3-EM2, BIOS H81EM2W08.308 08/25/2014
Jan  3 21:59:39 gauss kernel: task: 880087533300 ti:
880101ca8000 task.ti: 880101ca8000
Jan  3 21:59:39 gauss kernel: RIP: 0010:[]
[] vb2_core_qbuf+0x18/0x200 [videobuf2_core]
Jan  3 21:59:39 gauss kernel: RSP: 0018:880101cabe28  EFLAGS: 00010246
Jan  3 21:59:39 gauss kernel: RAX: 880087533300 RBX:
8800a9c98000 RCX: 03a5
Jan  3 21:59:39 gauss kernel: RDX: 8800a9c98000 RSI:
5e00 RDI: 88011995e828
Jan  3 21:59:39 gauss kernel: RBP: 880101cabe48 R08:
0007 R09: 0001
Jan  3 21:59:39 gauss kernel: R10:  R11:
88011995e828 R12: 88011a457780
Jan  3 21:59:39 gauss kernel: R13:  R14:
8800a9c98000 R15: 88011995e828
Jan  3 21:59:39 gauss kernel: FS:  ()
GS:88011fb0() knlGS:
Jan  3 21:59:39 gauss kernel: CS:  0010 DS:  ES:  CR0:
80050033
Jan  3 21:59:39 gauss kernel: CR2: 01a0 CR3:
b9e63000 CR4: 001406e0
Jan  3 21:59:39 gauss kernel: Stack:
Jan  3 21:59:39 gauss kernel:  8800a9c98000 88011a457780
 
Jan  3 21:59:39 gauss kernel:  880101cabeb8 a019f83c
88004550bb58 880087533300
Jan  3 21:59:39 gauss kernel:  8800a9c9a400 00cac000
88011995e828 a019f610
Jan  3 21:59:39 gauss kernel: Call Trace:
Jan  3 21:59:39 gauss kernel:  []
vb2_thread+0x22c/0x3c0 [videobuf2_core]
Jan  3 21:59:39 gauss kernel:  [] ?
vb2_core_dqbuf+0x5a0/0x5a0 [videobuf2_core]
Jan  3 21:59:39 gauss kernel:  [] ?
vb2_core_dqbuf+0x5a0/0x5a0 [videobuf2_core]
Jan  3 21:59:39 gauss kernel:  [] kthread+0xc4/0xe0
Jan  3 21:59:39 gauss kernel:  [] ?
kthread_worker_fn+0x150/0x150
Jan  3 21:59:39 gauss kernel:  [] ret_from_fork+0x3f/0x70
Jan  3 21:59:39 gauss kernel:  [] ?
kthread_worker_fn+0x150/0x150
Jan  3 21:59:39 gauss kernel: Code: c7 a8 1d 1a a0 e8 12 67 6f e1 31 c0
e9 70 ff ff ff 66 90 55 89 f6 48 89 e5 41 56 41 55 41 54 53 49 89 d6 4c
8b ac f7 80 00 00 00 <41> 8b 95 a0 01 00 00 83 fa 01 0f 84 fb 00 00 00
49 89 fc 0f 82
Jan  3 21:59:39 gauss kernel: RIP  []
vb2_core_qbuf+0x18/0x200 [videobuf2_core]
Jan  3 21:59:39 gauss kernel:  RSP 
Jan  3 21:59:39 gauss kernel: CR2: 01a0
Jan  3 21:59:39 gauss kernel: ---[ end trace f45084629c26b0e2 ]---

It oopses in vb2_core_qbuf+0x18
addr2line shows this:
media_build/v4l/videobuf2-core.c:1377

>From decodecode:
  13:   55  push   %rbp
  14:   89 f6   mov%esi,%esi
  16:   48 89 e5mov%rsp,%rbp
  19:   41 56   push   %r14
  1b:   41 55   push   %r13
  1d:   41 54   push   %r12
  1f:   53  push   %rbx
  20:   49 89 d6mov%rdx,%r14
  23:   4c 8b ac f7 80 00 00mov0x80(%rdi,%rsi,8),%r13
  2a:   00
  2b:*  41 8b 95 a0 01 00 00mov0x1a0(%r13),%edx <--
trapping instruction
  32:   83 fa 01cmp$0x1,%edx
  35:   0f 84 fb 00 00 00   je 0x136
  3b:   49 89 fcmov%rdi,%r12

1375: vb = q->bufs[index];
1376:
1377: switch (vb->state) {

The value vb (r13) is equal to 0 here.

I bisected the oops to this commit:
70433a152f0058404afb5496a9329e4e26b127df is the first bad commit
commit 70433a152f0058404afb5496a9329e4e26b127df
Author: Junghak Sung 
Date:   Tue Nov 3 08:16:41 2015 -0200

[media] media: videobuf2: Refactor vb2_fileio_data and vb2_thread

Replace v4l2-stuffs with common things in struct vb2_fileio_data and
vb2_thread().

Signed-off-by: Junghak Sung 
Signed-off-by: Geunyoung Kim 
Acked-by: Seung-Woo Kim 
Acked-by: Inki Dae 

Re: [PATCH] [media] si2165: Refactoring for si2165_writereg_mask8()

2016-01-04 Thread Matthias Schwarzott
Am 27.12.2015 um 18:33 schrieb SF Markus Elfring:
> From: Markus Elfring <elfr...@users.sourceforge.net>
> Date: Sun, 27 Dec 2015 18:23:57 +0100
> 
> This issue was detected by using the Coccinelle software.
> 
> 1. Let us return directly if a call of the si2165_readreg8()
>function failed.
> 
> 2. Reduce the scope for the local variables "ret" and "tmp" to one branch
>of an if statement.
> 
> 3. Delete the jump label "err" then.
> 
> 4. Return the value from a call of the si2165_writereg8() function
>without using an extra assignment for the variable "ret" at the end.
> 
> Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net>

The patch looks fine.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>

Regards
Matthias

PS: I am going to switch to regmap, but this change is not yet polished
and until now does not touch this function.

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


[PATCH] si2165: Reject DVB-T bandwidth auto mode

2015-12-03 Thread Matthias Schwarzott
The si2165 does not support bandwidth auto-detection.
Reject the request.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 1cf6e52..6fcd3ba 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -825,19 +825,19 @@ static int si2165_set_frontend_dvbt(struct dvb_frontend 
*fe)
struct si2165_state *state = fe->demodulator_priv;
u32 dvb_rate = 0;
u16 bw10k;
+   u32 bw_hz = p->bandwidth_hz;
 
dprintk("%s: called\n", __func__);
 
if (!state->has_dvbt)
return -EINVAL;
 
-   if (p->bandwidth_hz > 0) {
-   dvb_rate = p->bandwidth_hz * 8 / 7;
-   bw10k = p->bandwidth_hz / 1;
-   } else {
-   dvb_rate = 8 * 8 / 7;
-   bw10k = 800;
-   }
+   /* no bandwidth auto-detection */
+   if (bw_hz == 0)
+   return -EINVAL;
+
+   dvb_rate = bw_hz * 8 / 7;
+   bw10k = bw_hz / 1;
 
ret = si2165_adjust_pll_divl(state, 12);
if (ret < 0)
-- 
2.6.3

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


Re: [PATCH 07/10] si2165: Fix DVB-T bandwidth default

2015-12-03 Thread Matthias Schwarzott
Am 03.12.2015 um 15:15 schrieb Mauro Carvalho Chehab:
> Em Thu, 19 Nov 2015 21:03:59 +0100
> Matthias Schwarzott <z...@gentoo.org> escreveu:
> 
> 
> Please, add a description to your patches.
> 
> That's said, this patch should be called, instead:
> 
> si2165: Fix DVB-T bandwidth auto
> 
> DVB auto bandwidth mode (bandwidth_hz == 0) logic was setting
> the initial value for dvb_rate to a wrong value. Fix it.
> 
> as a zero value here means to let the frontend to auto-detect
> the bandwidth. Of course, assuming that si2165 is capable of
> doing that.
> 
> If si2165 chip or driver doesn't support bandwidth auto-detection, it
> should, instead, return -EINVAL.
> 
> Are you sure that it will auto-detect the bandwidth if we keep it
> as 8MHz?
> 

Thanks for the feedback.
As far as I know si2165 does not support auto-detection of bandwidth.

I only have 8MHz channels available I tried what happens when
configuring other bandwidth values - it will not lock.

So I will resend the modified the patch.

Regards
Matthias

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


[PATCH] tda10071: Fix dependency to REGMAP_I2C

2015-11-23 Thread Matthias Schwarzott
Without I get this error for by dvb-card:
  tda10071: Unknown symbol devm_regmap_init_i2c (err 0)
  cx23885_dvb_register() dvb_register failed err = -22
  cx23885_dev_setup() Failed to register dvb adapters on VID_B

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/Kconfig 
b/drivers/media/dvb-frontends/Kconfig
index 292c947..310e4b8 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -264,7 +264,7 @@ config DVB_MB86A16
 config DVB_TDA10071
tristate "NXP TDA10071"
depends on DVB_CORE && I2C
-   select REGMAP
+   select REGMAP_I2C
default m if !MEDIA_SUBDRV_AUTOSELECT
help
  Say Y when you want to support this frontend.
-- 
2.6.3

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


media_build using regmap-i2c

2015-11-23 Thread Matthias Schwarzott
Hi!

I noticed for a media_build installation, that tda10071 was not loadable
because regmap-i2c did not exist.

The only way I saw to get regmap-i2c compiled, is to enable any other
kernel module that has a "select REGMAP_I2C" in Kconfig.
I choose "CONFIG_SENSORS_ADS7828=m".

Maybe the kernel needs a way to enable this module "for external
drivers" as the "Library routines" folders.

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


Re: [PATCH 4/4] si2165: Add DVB-C support for HVR-4400/HVR-5500

2015-11-22 Thread Matthias Schwarzott
Am 19.11.2015 um 14:28 schrieb Mauro Carvalho Chehab:
> Em Fri, 13 Nov 2015 23:54:58 +0100
> Matthias Schwarzott <z...@gentoo.org> escreveu:
> 
>> It works only for HVR-4400/HVR-5500.
>> For WinTV-HVR-930C-HD it fails with bad/no reception
>> for unknown reasons.
> 
> Patch 3/4 of this series is broken. As this one depends on it, please
> resend both patches 3 and 4 on your next patch series.
> 
> Regards,
> Mauro
> 
> PS.: patches 1 and 2 are ok and got applied upstream already.
> 
> 
Hi Mauro,

if you did not notice, I split the patches down into more parts,
improved them a bit and sent them with subject "si2165: Add simple DVB-C
support".

Regards
Matthias

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


si2165: Add simple DVB-C support

2015-11-19 Thread Matthias Schwarzott
This series adds simple DVB-C support to the si2165 demod driver.

It works only for HVR-4400/HVR-5500.
For WinTV-HVR-930C-HD it fails with bad/no reception
for unknown reasons.

Regards
Matthias

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


[PATCH 09/10] si2165: Prepare si2165_set_frontend for splitting

2015-11-19 Thread Matthias Schwarzott
Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 51 ++--
 1 file changed, 37 insertions(+), 14 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 01c9a19..131aef1 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -760,7 +760,7 @@ static int si2165_set_oversamp(struct si2165_state *state, 
u32 dvb_rate)
do_div(oversamp, dvb_rate);
reg_value = oversamp & 0x3fff;
 
-   /* oversamp, usbdump contained 0x0310; */
+   dprintk("%s: Write oversamp=%#x\n", __func__, reg_value);
return si2165_writereg32(state, 0x00e4, reg_value);
 }
 
@@ -795,14 +795,6 @@ static int si2165_set_if_freq_shift(struct si2165_state 
*state)
return si2165_writereg32(state, 0x00e8, reg_value);
 }
 
-static const struct si2165_reg_value_pair agc_rewrite[] = {
-   { 0x012a, 0x46 },
-   { 0x012c, 0x00 },
-   { 0x012e, 0x0a },
-   { 0x012f, 0xff },
-   { 0x0123, 0x70 }
-};
-
 static const struct si2165_reg_value_pair dvbt_regs[] = {
/* standard = DVB-T */
{ 0x00ec, 0x01 },
@@ -826,12 +818,11 @@ static const struct si2165_reg_value_pair dvbt_regs[] = {
{ 0x0387, 0x00 }
 };
 
-static int si2165_set_frontend(struct dvb_frontend *fe)
+static int si2165_set_frontend_dvbt(struct dvb_frontend *fe)
 {
int ret;
struct dtv_frontend_properties *p = >dtv_property_cache;
struct si2165_state *state = fe->demodulator_priv;
-   u8 val[3];
u32 dvb_rate = 0;
u16 bw10k;
u32 bw_hz = p->bandwidth_hz;
@@ -851,9 +842,6 @@ static int si2165_set_frontend(struct dvb_frontend *fe)
if (ret < 0)
return ret;
 
-   ret = si2165_set_if_freq_shift(state);
-   if (ret < 0)
-   return ret;
/* bandwidth in 10KHz steps */
ret = si2165_writereg16(state, 0x0308, bw10k);
if (ret < 0)
@@ -866,6 +854,40 @@ static int si2165_set_frontend(struct dvb_frontend *fe)
if (ret < 0)
return ret;
 
+   return 0;
+}
+
+static const struct si2165_reg_value_pair agc_rewrite[] = {
+   { 0x012a, 0x46 },
+   { 0x012c, 0x00 },
+   { 0x012e, 0x0a },
+   { 0x012f, 0xff },
+   { 0x0123, 0x70 }
+};
+
+static int si2165_set_frontend(struct dvb_frontend *fe)
+{
+   struct si2165_state *state = fe->demodulator_priv;
+   struct dtv_frontend_properties *p = >dtv_property_cache;
+   u32 delsys = p->delivery_system;
+   int ret;
+   u8 val[3];
+
+   /* initial setting of if freq shift */
+   ret = si2165_set_if_freq_shift(state);
+   if (ret < 0)
+   return ret;
+
+   switch (delsys) {
+   case SYS_DVBT:
+   ret = si2165_set_frontend_dvbt(fe);
+   if (ret < 0)
+   return ret;
+   break;
+   default:
+   return -EINVAL;
+   }
+
/* dsp_addr_jump */
ret = si2165_writereg32(state, 0x0348, 0xf400);
if (ret < 0)
@@ -886,6 +908,7 @@ static int si2165_set_frontend(struct dvb_frontend *fe)
ret = si2165_writereg8(state, 0x0341, 0x00);
if (ret < 0)
return ret;
+
/* reset all */
ret = si2165_writereg8(state, 0x00c0, 0x00);
if (ret < 0)
-- 
2.6.3

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


[PATCH 02/10] si2165: rename si2165_set_parameters to si2165_set_frontend

2015-11-19 Thread Matthias Schwarzott
Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index d36b36c..a0e4600 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -767,7 +767,7 @@ static int si2165_set_if_freq_shift(struct si2165_state 
*state, u32 IF)
return si2165_writereg32(state, 0x00e8, reg_value);
 }
 
-static int si2165_set_parameters(struct dvb_frontend *fe)
+static int si2165_set_frontend(struct dvb_frontend *fe)
 {
int ret;
struct dtv_frontend_properties *p = >dtv_property_cache;
@@ -952,7 +952,7 @@ static struct dvb_frontend_ops si2165_ops = {
.init = si2165_init,
.sleep = si2165_sleep,
 
-   .set_frontend  = si2165_set_parameters,
+   .set_frontend  = si2165_set_frontend,
.read_status   = si2165_read_status,
 
.release = si2165_release,
-- 
2.6.3

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


[PATCH 07/10] si2165: Fix DVB-T bandwidth default

2015-11-19 Thread Matthias Schwarzott
Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 807a3c9..e97b0e6 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -811,19 +811,18 @@ static int si2165_set_frontend(struct dvb_frontend *fe)
u8 val[3];
u32 dvb_rate = 0;
u16 bw10k;
+   u32 bw_hz = p->bandwidth_hz;
 
dprintk("%s: called\n", __func__);
 
if (!state->has_dvbt)
return -EINVAL;
 
-   if (p->bandwidth_hz > 0) {
-   dvb_rate = p->bandwidth_hz * 8 / 7;
-   bw10k = p->bandwidth_hz / 1;
-   } else {
-   dvb_rate = 8 * 8 / 7;
-   bw10k = 800;
-   }
+   if (bw_hz == 0)
+   bw_hz = 800;
+
+   dvb_rate = bw_hz * 8 / 7;
+   bw10k = bw_hz / 1;
 
/* standard = DVB-T */
ret = si2165_writereg8(state, 0x00ec, 0x01);
-- 
2.6.3

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


[PATCH 06/10] si2165: Simplify si2165_set_if_freq_shift usage

2015-11-19 Thread Matthias Schwarzott
Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 0c1f4c4..807a3c9 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -764,12 +764,22 @@ static int si2165_set_oversamp(struct si2165_state 
*state, u32 dvb_rate)
return si2165_writereg32(state, 0x00e4, reg_value);
 }
 
-static int si2165_set_if_freq_shift(struct si2165_state *state, u32 IF)
+static int si2165_set_if_freq_shift(struct si2165_state *state)
 {
+   struct dvb_frontend *fe = >fe;
u64 if_freq_shift;
s32 reg_value = 0;
u32 fe_clk = si2165_get_fe_clk(state);
+   u32 IF = 0;
 
+   if (!fe->ops.tuner_ops.get_if_frequency) {
+   dev_err(>i2c->dev,
+   "%s: Error: get_if_frequency() not defined at tuner. 
Can't work without it!\n",
+   KBUILD_MODNAME);
+   return -EINVAL;
+   }
+
+   fe->ops.tuner_ops.get_if_frequency(fe, );
if_freq_shift = IF;
if_freq_shift <<= 29;
 
@@ -799,19 +809,11 @@ static int si2165_set_frontend(struct dvb_frontend *fe)
struct dtv_frontend_properties *p = >dtv_property_cache;
struct si2165_state *state = fe->demodulator_priv;
u8 val[3];
-   u32 IF;
u32 dvb_rate = 0;
u16 bw10k;
 
dprintk("%s: called\n", __func__);
 
-   if (!fe->ops.tuner_ops.get_if_frequency) {
-   dev_err(>i2c->dev,
-   "%s: Error: get_if_frequency() not defined at tuner. 
Can't work without it!\n",
-   KBUILD_MODNAME);
-   return -EINVAL;
-   }
-
if (!state->has_dvbt)
return -EINVAL;
 
@@ -831,8 +833,7 @@ static int si2165_set_frontend(struct dvb_frontend *fe)
if (ret < 0)
return ret;
 
-   fe->ops.tuner_ops.get_if_frequency(fe, );
-   ret = si2165_set_if_freq_shift(state, IF);
+   ret = si2165_set_if_freq_shift(state);
if (ret < 0)
return ret;
ret = si2165_writereg8(state, 0x08f8, 0x00);
@@ -896,8 +897,7 @@ static int si2165_set_frontend(struct dvb_frontend *fe)
fe->ops.tuner_ops.set_params(fe);
 
/* recalc if_freq_shift if IF might has changed */
-   fe->ops.tuner_ops.get_if_frequency(fe, );
-   ret = si2165_set_if_freq_shift(state, IF);
+   ret = si2165_set_if_freq_shift(state);
if (ret < 0)
return ret;
 
-- 
2.6.3

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


[PATCH 04/10] si2165: only write agc registers after reset before start_syncro

2015-11-19 Thread Matthias Schwarzott
Datasheet says they must be rewritten after reset.
But it only makes sense to write them when trying to tune afterwards.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 32 +++-
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 222d775..07247e3 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -690,23 +690,6 @@ static int si2165_init(struct dvb_frontend *fe)
goto error;
}
 
-   /* write adc values after each reset*/
-   ret = si2165_writereg8(state, 0x012a, 0x46);
-   if (ret < 0)
-   goto error;
-   ret = si2165_writereg8(state, 0x012c, 0x00);
-   if (ret < 0)
-   goto error;
-   ret = si2165_writereg8(state, 0x012e, 0x0a);
-   if (ret < 0)
-   goto error;
-   ret = si2165_writereg8(state, 0x012f, 0xff);
-   if (ret < 0)
-   goto error;
-   ret = si2165_writereg8(state, 0x0123, 0x70);
-   if (ret < 0)
-   goto error;
-
return 0;
 error:
return ret;
@@ -788,6 +771,14 @@ static int si2165_set_if_freq_shift(struct si2165_state 
*state, u32 IF)
return si2165_writereg32(state, 0x00e8, reg_value);
 }
 
+static const struct si2165_reg_value_pair agc_rewrite[] = {
+   { 0x012a, 0x46 },
+   { 0x012c, 0x00 },
+   { 0x012e, 0x0a },
+   { 0x012f, 0xff },
+   { 0x0123, 0x70 }
+};
+
 static int si2165_set_frontend(struct dvb_frontend *fe)
 {
int ret;
@@ -924,6 +915,13 @@ static int si2165_set_frontend(struct dvb_frontend *fe)
ret = si2165_writereg32(state, 0x0384, 0x);
if (ret < 0)
return ret;
+
+   /* write adc values after each reset*/
+   ret = si2165_write_reg_list(state, agc_rewrite,
+   ARRAY_SIZE(agc_rewrite));
+   if (ret < 0)
+   return ret;
+
/* start_synchro */
ret = si2165_writereg8(state, 0x02e0, 0x01);
if (ret < 0)
-- 
2.6.3

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


[PATCH 10/10] si2165: Add DVB-C support for HVR-4400/HVR-5500

2015-11-19 Thread Matthias Schwarzott
It works only for HVR-4400/HVR-5500.
For WinTV-HVR-930C-HD it fails with bad/no reception
for unknown reasons.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 86 +---
 1 file changed, 81 insertions(+), 5 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 131aef1..dd4503a 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -857,6 +857,71 @@ static int si2165_set_frontend_dvbt(struct dvb_frontend 
*fe)
return 0;
 }
 
+static const struct si2165_reg_value_pair dvbc_regs[] = {
+   /* standard = DVB-C */
+   { 0x00ec, 0x05 },
+   { 0x08f8, 0x00 },
+
+   /* agc2 */
+   { 0x016e, 0x50 },
+   { 0x016c, 0x0e },
+   { 0x016d, 0x10 },
+   /* agc */
+   { 0x015b, 0x03 },
+   { 0x0150, 0x68 },
+   /* agc */
+   { 0x01a0, 0x68 },
+   { 0x01c8, 0x50 },
+
+   { 0x0278, 0x0d },
+
+   { 0x023a, 0x05 },
+   { 0x0261, 0x09 },
+   REG16(0x0350, 0x3e80),
+   { 0x02f4, 0x00 },
+
+   { 0x00cb, 0x01 },
+   REG16(0x024c, 0x),
+   REG16(0x027c, 0x),
+   { 0x0232, 0x03 },
+   { 0x02f4, 0x0b },
+   { 0x018b, 0x00 },
+};
+
+static int si2165_set_frontend_dvbc(struct dvb_frontend *fe)
+{
+   struct si2165_state *state = fe->demodulator_priv;
+   int ret;
+   struct dtv_frontend_properties *p = >dtv_property_cache;
+   const u32 dvb_rate = p->symbol_rate;
+   const u32 bw_hz = p->bandwidth_hz;
+
+   if (!state->has_dvbc)
+   return -EINVAL;
+
+   if (dvb_rate == 0)
+   return -EINVAL;
+
+   ret = si2165_adjust_pll_divl(state, 14);
+   if (ret < 0)
+   return ret;
+
+   /* Oversampling */
+   ret = si2165_set_oversamp(state, dvb_rate);
+   if (ret < 0)
+   return ret;
+
+   ret = si2165_writereg32(state, 0x00c4, bw_hz);
+   if (ret < 0)
+   return ret;
+
+   ret = si2165_write_reg_list(state, dvbc_regs, ARRAY_SIZE(dvbc_regs));
+   if (ret < 0)
+   return ret;
+
+   return 0;
+}
+
 static const struct si2165_reg_value_pair agc_rewrite[] = {
{ 0x012a, 0x46 },
{ 0x012c, 0x00 },
@@ -884,6 +949,11 @@ static int si2165_set_frontend(struct dvb_frontend *fe)
if (ret < 0)
return ret;
break;
+   case SYS_DVBC_ANNEX_A:
+   ret = si2165_set_frontend_dvbc(fe);
+   if (ret < 0)
+   return ret;
+   break;
default:
return -EINVAL;
}
@@ -947,7 +1017,12 @@ static void si2165_release(struct dvb_frontend *fe)
 static struct dvb_frontend_ops si2165_ops = {
.info = {
.name = "Silicon Labs ",
-   .caps = FE_CAN_FEC_1_2 |
+/* For DVB-C */
+   .symbol_rate_min = 100,
+   .symbol_rate_max = 720,
+   /* For DVB-T */
+   .frequency_stepsize = 17,
+   .caps = FE_CAN_FEC_1_2 |
FE_CAN_FEC_2_3 |
FE_CAN_FEC_3_4 |
FE_CAN_FEC_5_6 |
@@ -960,7 +1035,6 @@ static struct dvb_frontend_ops si2165_ops = {
FE_CAN_QAM_128 |
FE_CAN_QAM_256 |
FE_CAN_QAM_AUTO |
-   FE_CAN_TRANSMISSION_MODE_AUTO |
FE_CAN_GUARD_INTERVAL_AUTO |
FE_CAN_HIERARCHY_AUTO |
FE_CAN_MUTE_TS |
@@ -1072,9 +1146,11 @@ struct dvb_frontend *si2165_attach(const struct 
si2165_config *config,
strlcat(state->fe.ops.info.name, " DVB-T",
sizeof(state->fe.ops.info.name));
}
-   if (state->has_dvbc)
-   dev_warn(>i2c->dev, "%s: DVB-C is not yet supported.\n",
-  KBUILD_MODNAME);
+   if (state->has_dvbc) {
+   state->fe.ops.delsys[n++] = SYS_DVBC_ANNEX_A;
+   strlcat(state->fe.ops.info.name, " DVB-C",
+   sizeof(state->fe.ops.info.name));
+   }
 
return >fe;
 
-- 
2.6.3

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


[PATCH 08/10] si2165: set list of DVB-T registers together

2015-11-19 Thread Matthias Schwarzott
Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 73 +---
 1 file changed, 26 insertions(+), 47 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index e97b0e6..01c9a19 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -803,6 +803,29 @@ static const struct si2165_reg_value_pair agc_rewrite[] = {
{ 0x0123, 0x70 }
 };
 
+static const struct si2165_reg_value_pair dvbt_regs[] = {
+   /* standard = DVB-T */
+   { 0x00ec, 0x01 },
+   { 0x08f8, 0x00 },
+   /* impulsive_noise_remover */
+   { 0x031c, 0x01 },
+   { 0x00cb, 0x00 },
+   /* agc2 */
+   { 0x016e, 0x41 },
+   { 0x016c, 0x0e },
+   { 0x016d, 0x10 },
+   /* agc */
+   { 0x015b, 0x03 },
+   { 0x0150, 0x78 },
+   /* agc */
+   { 0x01a0, 0x78 },
+   { 0x01c8, 0x68 },
+   /* freq_sync_range */
+   REG16(0x030c, 0x0064),
+   /* gp_reg0 */
+   { 0x0387, 0x00 }
+};
+
 static int si2165_set_frontend(struct dvb_frontend *fe)
 {
int ret;
@@ -824,10 +847,6 @@ static int si2165_set_frontend(struct dvb_frontend *fe)
dvb_rate = bw_hz * 8 / 7;
bw10k = bw_hz / 1;
 
-   /* standard = DVB-T */
-   ret = si2165_writereg8(state, 0x00ec, 0x01);
-   if (ret < 0)
-   return ret;
ret = si2165_adjust_pll_divl(state, 12);
if (ret < 0)
return ret;
@@ -835,9 +854,6 @@ static int si2165_set_frontend(struct dvb_frontend *fe)
ret = si2165_set_if_freq_shift(state);
if (ret < 0)
return ret;
-   ret = si2165_writereg8(state, 0x08f8, 0x00);
-   if (ret < 0)
-   return ret;
/* bandwidth in 10KHz steps */
ret = si2165_writereg16(state, 0x0308, bw10k);
if (ret < 0)
@@ -845,48 +861,11 @@ static int si2165_set_frontend(struct dvb_frontend *fe)
ret = si2165_set_oversamp(state, dvb_rate);
if (ret < 0)
return ret;
-   /* impulsive_noise_remover */
-   ret = si2165_writereg8(state, 0x031c, 0x01);
-   if (ret < 0)
-   return ret;
-   ret = si2165_writereg8(state, 0x00cb, 0x00);
-   if (ret < 0)
-   return ret;
-   /* agc2 */
-   ret = si2165_writereg8(state, 0x016e, 0x41);
-   if (ret < 0)
-   return ret;
-   ret = si2165_writereg8(state, 0x016c, 0x0e);
-   if (ret < 0)
-   return ret;
-   ret = si2165_writereg8(state, 0x016d, 0x10);
-   if (ret < 0)
-   return ret;
-   /* agc */
-   ret = si2165_writereg8(state, 0x015b, 0x03);
-   if (ret < 0)
-   return ret;
-   ret = si2165_writereg8(state, 0x0150, 0x78);
-   if (ret < 0)
-   return ret;
-   /* agc */
-   ret = si2165_writereg8(state, 0x01a0, 0x78);
-   if (ret < 0)
-   return ret;
-   ret = si2165_writereg8(state, 0x01c8, 0x68);
-   if (ret < 0)
-   return ret;
-   /* freq_sync_range */
-   ret = si2165_writereg16(state, 0x030c, 0x0064);
-   if (ret < 0)
-   return ret;
-   /* gp_reg0 */
-   ret = si2165_readreg8(state, 0x0387, val);
-   if (ret < 0)
-   return ret;
-   ret = si2165_writereg8(state, 0x0387, 0x00);
+
+   ret = si2165_write_reg_list(state, dvbt_regs, ARRAY_SIZE(dvbt_regs));
if (ret < 0)
return ret;
+
/* dsp_addr_jump */
ret = si2165_writereg32(state, 0x0348, 0xf400);
if (ret < 0)
-- 
2.6.3

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


[PATCH 03/10] si2165: create function si2165_write_reg_list for writing register lists

2015-11-19 Thread Matthias Schwarzott
Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 21 +
 1 file changed, 21 insertions(+)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index a0e4600..222d775 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -243,6 +243,27 @@ err:
return ret;
 }
 
+#define REG16(reg, val) { (reg), (val) & 0xff }, { (reg)+1, (val)>>8 & 0xff }
+struct si2165_reg_value_pair {
+   u16 reg;
+   u8 val;
+};
+
+static int si2165_write_reg_list(struct si2165_state *state,
+const struct si2165_reg_value_pair *regs,
+int count)
+{
+   int i;
+   int ret;
+
+   for (i = 0; i < count; i++) {
+   ret = si2165_writereg8(state, regs[i].reg, regs[i].val);
+   if (ret < 0)
+   return ret;
+   }
+   return 0;
+}
+
 static int si2165_get_tune_settings(struct dvb_frontend *fe,
struct dvb_frontend_tune_settings *s)
 {
-- 
2.6.3

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


[PATCH 05/10] si2165: move setting ts config to init

2015-11-19 Thread Matthias Schwarzott
The TS config is fixed, so no need to write it for each tune.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 27 ++-
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 07247e3..0c1f4c4 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -690,6 +690,20 @@ static int si2165_init(struct dvb_frontend *fe)
goto error;
}
 
+   /* ts output config */
+   ret = si2165_writereg8(state, 0x04e4, 0x20);
+   if (ret < 0)
+   return ret;
+   ret = si2165_writereg16(state, 0x04ef, 0x00fe);
+   if (ret < 0)
+   return ret;
+   ret = si2165_writereg24(state, 0x04f4, 0x55);
+   if (ret < 0)
+   return ret;
+   ret = si2165_writereg8(state, 0x04e5, 0x01);
+   if (ret < 0)
+   return ret;
+
return 0;
 error:
return ret;
@@ -824,19 +838,6 @@ static int si2165_set_frontend(struct dvb_frontend *fe)
ret = si2165_writereg8(state, 0x08f8, 0x00);
if (ret < 0)
return ret;
-   /* ts output config */
-   ret = si2165_writereg8(state, 0x04e4, 0x20);
-   if (ret < 0)
-   return ret;
-   ret = si2165_writereg16(state, 0x04ef, 0x00fe);
-   if (ret < 0)
-   return ret;
-   ret = si2165_writereg24(state, 0x04f4, 0x55);
-   if (ret < 0)
-   return ret;
-   ret = si2165_writereg8(state, 0x04e5, 0x01);
-   if (ret < 0)
-   return ret;
/* bandwidth in 10KHz steps */
ret = si2165_writereg16(state, 0x0308, bw10k);
if (ret < 0)
-- 
2.6.3

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


[PATCH 01/10] si2165: rename frontend -> fe

2015-11-19 Thread Matthias Schwarzott
Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index c5d7c0d..d36b36c 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -42,7 +42,7 @@
 struct si2165_state {
struct i2c_adapter *i2c;
 
-   struct dvb_frontend frontend;
+   struct dvb_frontend fe;
 
struct si2165_config config;
 
@@ -988,9 +988,9 @@ struct dvb_frontend *si2165_attach(const struct 
si2165_config *config,
}
 
/* create dvb_frontend */
-   memcpy(>frontend.ops, _ops,
+   memcpy(>fe.ops, _ops,
sizeof(struct dvb_frontend_ops));
-   state->frontend.demodulator_priv = state;
+   state->fe.demodulator_priv = state;
 
/* powerup */
io_ret = si2165_writereg8(state, 0x, state->config.chip_mode);
@@ -1042,20 +1042,20 @@ struct dvb_frontend *si2165_attach(const struct 
si2165_config *config,
KBUILD_MODNAME, chip_name, rev_char, state->chip_type,
state->chip_revcode);
 
-   strlcat(state->frontend.ops.info.name, chip_name,
-   sizeof(state->frontend.ops.info.name));
+   strlcat(state->fe.ops.info.name, chip_name,
+   sizeof(state->fe.ops.info.name));
 
n = 0;
if (state->has_dvbt) {
-   state->frontend.ops.delsys[n++] = SYS_DVBT;
-   strlcat(state->frontend.ops.info.name, " DVB-T",
-   sizeof(state->frontend.ops.info.name));
+   state->fe.ops.delsys[n++] = SYS_DVBT;
+   strlcat(state->fe.ops.info.name, " DVB-T",
+   sizeof(state->fe.ops.info.name));
}
if (state->has_dvbc)
dev_warn(>i2c->dev, "%s: DVB-C is not yet supported.\n",
   KBUILD_MODNAME);
 
-   return >frontend;
+   return >fe;
 
 error:
kfree(state);
-- 
2.6.3

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


[PATCH 4/4] si2165: Add DVB-C support for HVR-4400/HVR-5500

2015-11-13 Thread Matthias Schwarzott
It works only for HVR-4400/HVR-5500.
For WinTV-HVR-930C-HD it fails with bad/no reception
for unknown reasons.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 132 +++
 1 file changed, 120 insertions(+), 12 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index c87d927..97a6eac 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -760,7 +760,7 @@ static int si2165_set_oversamp(struct si2165_state *state, 
u32 dvb_rate)
do_div(oversamp, dvb_rate);
reg_value = oversamp & 0x3fff;
 
-   /* oversamp, usbdump contained 0x0310; */
+   dprintk("%s: Write oversamp=%#x\n", __func__, reg_value);
return si2165_writereg32(state, 0x00e4, reg_value);
 }
 
@@ -823,7 +823,7 @@ static const struct si2165_reg_value_pair dvbt_regs[] = {
{ 0x0387, 0x00 }
 };
 
-static int si2165_set_parameters(struct dvb_frontend *fe)
+static int si2165_set_frontend_dvbt(struct dvb_frontend *fe)
 {
int ret;
struct dtv_frontend_properties *p = >dtv_property_cache;
@@ -851,9 +851,6 @@ static int si2165_set_parameters(struct dvb_frontend *fe)
if (ret < 0)
return ret;
 
-   ret = si2165_set_if_freq_shift(state);
-   if (ret < 0)
-   return ret;
ret = si2165_writereg8(state, 0x08f8, 0x00);
if (ret < 0)
return ret;
@@ -874,6 +871,110 @@ static int si2165_set_parameters(struct dvb_frontend *fe)
if (ret < 0)
return ret;
 
+   return 0;
+}
+
+static const struct si2165_reg_value_pair dvbc_regs[] = {
+   /* agc2 */
+   { 0x016e, 0x50 },
+   { 0x016c, 0x0e },
+   { 0x016d, 0x10 },
+   /* agc */
+   { 0x015b, 0x03 },
+   { 0x0150, 0x68 },
+   /* agc */
+   { 0x01a0, 0x68 },
+   { 0x01c8, 0x50 },
+
+   { 0x0278, 0x0d },
+
+   { 0x023a, 0x05 },
+   { 0x0261, 0x09 },
+   REG16(0x0350, 0x3e80),
+   { 0x02f4, 0x00 }
+};
+
+static int si2165_set_frontend_dvbc(struct dvb_frontend *fe)
+{
+   struct si2165_state *state = fe->demodulator_priv;
+   int ret;
+   struct dtv_frontend_properties *p = >dtv_property_cache;
+   const u32 dvb_rate = p->symbol_rate;
+   const u32 bw_hz = p->bandwidth_hz;
+
+   if (!state->has_dvbc)
+   return -EINVAL;
+
+   if (dvb_rate == 0)
+   return -EINVAL;
+
+   /* standard = DVB-C */
+   ret = si2165_writereg8(state, 0x00ec, 0x05);
+   if (ret < 0)
+   return ret;
+   ret = si2165_adjust_pll_divl(state, 14);
+   if (ret < 0)
+   return ret;
+
+   ret = si2165_writereg8(state, 0x08f8, 0x00);
+   if (ret < 0)
+   return ret;
+
+   /* Oversampling */
+   ret = si2165_set_oversamp(state, dvb_rate);
+   if (ret < 0)
+   return ret;
+
+   ret = si2165_write_reg_list(state, dvbc_regs, ARRAY_SIZE(dvbc_regs));
+   if (ret < 0)
+   return ret;
+
+   /* dsp_addr_jump */
+   ret = si2165_writereg32(state, 0x0348, 0xf400);
+   if (ret < 0)
+   return ret;
+
+   si2165_writereg32(state, 0x00c4, bw_hz);
+   si2165_writereg8(state, 0x00cb, 0x01);
+   si2165_writereg8(state, 0x00c0, 0x00);
+   si2165_writereg16(state, 0x024c, 0x);
+   si2165_writereg16(state, 0x027c, 0x);
+   si2165_writereg8(state, 0x0232, 0x03);
+   si2165_writereg8(state, 0x02f4, 0x0b);
+   si2165_writereg8(state, 0x00c0, 0x00);
+   si2165_writereg8(state, 0x018b, 0x00);
+
+   return 0;
+}
+
+static int si2165_set_frontend(struct dvb_frontend *fe)
+{
+   struct si2165_state *state = fe->demodulator_priv;
+   struct dtv_frontend_properties *p = >dtv_property_cache;
+   u32 delsys = p->delivery_system;
+   int ret;
+   u8 val[3];
+
+   /* initial setting of if freq shift */
+   ret = si2165_set_if_freq_shift(state);
+   if (ret < 0)
+   return ret;
+
+   switch (delsys) {
+   case SYS_DVBT:
+   ret = si2165_set_frontend_dvbt(fe);
+   if (ret < 0)
+   return ret;
+   break;
+   case SYS_DVBC_ANNEX_A:
+   ret = si2165_set_frontend_dvbc(fe);
+   if (ret < 0)
+   return ret;
+   break;
+   default:
+   return -EINVAL;
+   }
+
if (fe->ops.tuner_ops.set_params)
fe->ops.tuner_ops.set_params(fe);
 
@@ -889,6 +990,7 @@ static int si2165_set_parameters(struct dvb_frontend *fe)
ret = si2165_writereg8(state, 0x0341, 0x00);
if (ret < 0)
return ret;
+
/* reset all */
ret = si2165_writereg8(state, 0x00c0, 0x00);
   

[PATCH 3/4] si2165: cleanup logic

2015-11-13 Thread Matthias Schwarzott
Make si2165_set_if_freq_shift query IF frequency itself.
create function to write a set of registers
Always write adc registers after reset.

Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 173 ++-
 1 file changed, 87 insertions(+), 86 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index c5d7c0d..c87d927 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -243,6 +243,27 @@ err:
return ret;
 }
 
+#define REG16(reg, val) { (reg), (val) & 0xff }, { (reg)+1, (val)>>8 & 0xff }
+struct si2165_reg_value_pair {
+   u16 reg;
+   u8 val;
+};
+
+static int si2165_write_reg_list(struct si2165_state *state,
+const struct si2165_reg_value_pair *regs,
+int count)
+{
+   int i;
+   int ret;
+
+   for (i = 0; i < count; i++) {
+   ret = si2165_writereg8(state, regs[i].reg, regs[i].val);
+   if (ret < 0)
+   return ret;
+   }
+   return 0;
+}
+
 static int si2165_get_tune_settings(struct dvb_frontend *fe,
struct dvb_frontend_tune_settings *s)
 {
@@ -669,22 +690,19 @@ static int si2165_init(struct dvb_frontend *fe)
goto error;
}
 
-   /* write adc values after each reset*/
-   ret = si2165_writereg8(state, 0x012a, 0x46);
-   if (ret < 0)
-   goto error;
-   ret = si2165_writereg8(state, 0x012c, 0x00);
+   /* ts output config */
+   ret = si2165_writereg8(state, 0x04e4, 0x20);
if (ret < 0)
-   goto error;
-   ret = si2165_writereg8(state, 0x012e, 0x0a);
+   return ret;
+   ret = si2165_writereg16(state, 0x04ef, 0x00fe);
if (ret < 0)
-   goto error;
-   ret = si2165_writereg8(state, 0x012f, 0xff);
+   return ret;
+   ret = si2165_writereg24(state, 0x04f4, 0x55);
if (ret < 0)
-   goto error;
-   ret = si2165_writereg8(state, 0x0123, 0x70);
+   return ret;
+   ret = si2165_writereg8(state, 0x04e5, 0x01);
if (ret < 0)
-   goto error;
+   return ret;
 
return 0;
 error:
@@ -746,12 +764,22 @@ static int si2165_set_oversamp(struct si2165_state 
*state, u32 dvb_rate)
return si2165_writereg32(state, 0x00e4, reg_value);
 }
 
-static int si2165_set_if_freq_shift(struct si2165_state *state, u32 IF)
+static int si2165_set_if_freq_shift(struct si2165_state *state)
 {
+   struct dvb_frontend *fe = &(state->frontend);
u64 if_freq_shift;
s32 reg_value = 0;
u32 fe_clk = si2165_get_fe_clk(state);
+   u32 IF = 0;
+
+   if (!fe->ops.tuner_ops.get_if_frequency) {
+   dev_err(>i2c->dev,
+   "%s: Error: get_if_frequency() not defined at tuner. 
Can't work without it!\n",
+   KBUILD_MODNAME);
+   return -EINVAL;
+   }
 
+   fe->ops.tuner_ops.get_if_frequency(fe, );
if_freq_shift = IF;
if_freq_shift <<= 29;
 
@@ -767,35 +795,53 @@ static int si2165_set_if_freq_shift(struct si2165_state 
*state, u32 IF)
return si2165_writereg32(state, 0x00e8, reg_value);
 }
 
+static const struct si2165_reg_value_pair agc_rewrite[] = {
+   { 0x012a, 0x46 },
+   { 0x012c, 0x00 },
+   { 0x012e, 0x0a },
+   { 0x012f, 0xff },
+   { 0x0123, 0x70 }
+};
+
+static const struct si2165_reg_value_pair dvbt_regs[] = {
+   /* impulsive_noise_remover */
+   { 0x031c, 0x01 },
+   { 0x00cb, 0x00 },
+   /* agc2 */
+   { 0x016e, 0x41 },
+   { 0x016c, 0x0e },
+   { 0x016d, 0x10 },
+   /* agc */
+   { 0x015b, 0x03 },
+   { 0x0150, 0x78 },
+   /* agc */
+   { 0x01a0, 0x78 },
+   { 0x01c8, 0x68 },
+   /* freq_sync_range */
+   REG16(0x030c, 0x0064),
+   /* gp_reg0 */
+   { 0x0387, 0x00 }
+};
+
 static int si2165_set_parameters(struct dvb_frontend *fe)
 {
int ret;
struct dtv_frontend_properties *p = >dtv_property_cache;
struct si2165_state *state = fe->demodulator_priv;
-   u8 val[3];
-   u32 IF;
u32 dvb_rate = 0;
u16 bw10k;
+   u32 bw_hz = p->bandwidth_hz;
 
dprintk("%s: called\n", __func__);
 
-   if (!fe->ops.tuner_ops.get_if_frequency) {
-   dev_err(>i2c->dev,
-   "%s: Error: get_if_frequency() not defined at tuner. 
Can't work without it!\n",
-   KBUILD_MODNAME);
-   return -EINVAL;
-   }
-
if (!state->has_dvbt)
return -EINVAL;
 
-   if (p->bandwidth_hz > 0) {
-   dvb_rate = p-&g

[PATCH 2/4] si2165: fix checkpatch issues

2015-11-13 Thread Matthias Schwarzott
Signed-off-by: Matthias Schwarzott <z...@gentoo.org>
---
 drivers/media/dvb-frontends/si2165.c | 69 
 1 file changed, 39 insertions(+), 30 deletions(-)

diff --git a/drivers/media/dvb-frontends/si2165.c 
b/drivers/media/dvb-frontends/si2165.c
index 7c2..c5d7c0d 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -1,21 +1,21 @@
 /*
-Driver for Silicon Labs Si2161 DVB-T and Si2165 DVB-C/-T Demodulator
-
-Copyright (C) 2013-2014 Matthias Schwarzott <z...@gentoo.org>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-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.
-
-References:
-http://www.silabs.com/Support%20Documents/TechnicalDocs/Si2165-short.pdf
-*/
+ *  Driver for Silicon Labs Si2161 DVB-T and Si2165 DVB-C/-T Demodulator
+ *
+ *  Copyright (C) 2013-2014 Matthias Schwarzott <z...@gentoo.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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.
+ *
+ *  References:
+ *  http://www.silabs.com/Support%20Documents/TechnicalDocs/Si2165-short.pdf
+ */
 
 #include 
 #include 
@@ -31,11 +31,13 @@
 #include "si2165_priv.h"
 #include "si2165.h"
 
-/* Hauppauge WinTV-HVR-930C-HD B130 / PCTV QuatroStick 521e 1113xx
- * uses 16 MHz xtal */
-
-/* Hauppauge WinTV-HVR-930C-HD B131 / PCTV QuatroStick 522e 1114xx
- * uses 24 MHz clock provided by tuner */
+/*
+ * Hauppauge WinTV-HVR-930C-HD B130 / PCTV QuatroStick 521e 1113xx
+ * uses 16 MHz xtal
+ *
+ * Hauppauge WinTV-HVR-930C-HD B131 / PCTV QuatroStick 522e 1114xx
+ * uses 24 MHz clock provided by tuner
+ */
 
 struct si2165_state {
struct i2c_adapter *i2c;
@@ -258,8 +260,10 @@ static int si2165_init_pll(struct si2165_state *state)
u8 divl = 12;
u8 buf[4];
 
-   /* hardcoded values can be deleted if calculation is verified
-* or it yields the same values as the windows driver */
+   /*
+* hardcoded values can be deleted if calculation is verified
+* or it yields the same values as the windows driver
+*/
switch (ref_freq_Hz) {
case 1600u:
divn = 56;
@@ -274,8 +278,10 @@ static int si2165_init_pll(struct si2165_state *state)
if (ref_freq_Hz > 1600u)
divr = 2;
 
-   /* now select divn and divp such that
-* fvco is in 1624..1824 MHz */
+   /*
+* now select divn and divp such that
+* fvco is in 1624..1824 MHz
+*/
if (162400u * divr > ref_freq_Hz * 2u * 63u)
divp = 4;
 
@@ -341,10 +347,12 @@ static int si2165_upload_firmware_block(struct 
si2165_state *state,
if (len % 4 != 0)
return -EINVAL;
 
-   deb_fw_load("si2165_upload_firmware_block called with len=0x%x 
offset=0x%x blockcount=0x%x\n",
+   deb_fw_load(
+   "si2165_upload_firmware_block called with len=0x%x offset=0x%x 
blockcount=0x%x\n",
len, offset, block_count);
while (offset+12 <= len && cur_block < block_count) {
-   deb_fw_load("si2165_upload_firmware_block in while len=0x%x 
offset=0x%x cur_block=0x%x blockcount=0x%x\n",
+   deb_fw_load(
+   "si2165_upload_firmware_block in while len=0x%x 
offset=0x%x cur_block=0x%x blockcount=0x%x\n",
len, offset, cur_block, block_count);
wordcount = data[offset];
if (wordcount < 1 || data[offset+1] ||
@@ -383,7 +391,8 @@ static int si2165_upload_firmware_block(struct si2165_state 
*state,
cur_block++;
}
 
-   deb_fw_load("si2165_upload_firmware_block after while len=0x%x 
offset=0x%x cur_block=0x%x blockcount=0x%x\n",
+   deb_fw_load(
+   "si2165_upload_firmware_block after while len=0x%x offset=0x%x 
cur_block=0x%x blockcount=0x%x\n",
len, o

Re: [PATCH] [media] si2165: Fix possible leak in si2165_upload_firmware()

2015-02-11 Thread Matthias Schwarzott
On 11.02.2015 21:58, Christian Engelmayer wrote:
 In case of an error function si2165_upload_firmware() releases the already
 requested firmware in the exit path. However, there is one deviation where
 the function directly returns. Use the correct cleanup so that the firmware
 memory gets freed correctly. Detected by Coverity CID 1269120.
 
 Signed-off-by: Christian Engelmayer cenge...@gmx.at
 ---
 Compile tested only. Applies against linux-next.
 ---
  drivers/media/dvb-frontends/si2165.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
 
 diff --git a/drivers/media/dvb-frontends/si2165.c 
 b/drivers/media/dvb-frontends/si2165.c
 index 98ddb49ad52b..4cc5d10ed0d4 100644
 --- a/drivers/media/dvb-frontends/si2165.c
 +++ b/drivers/media/dvb-frontends/si2165.c
 @@ -505,7 +505,7 @@ static int si2165_upload_firmware(struct si2165_state 
 *state)
   /* reset crc */
   ret = si2165_writereg8(state, 0x0379, 0x01);
   if (ret)
 - return ret;
 + goto error;
  
   ret = si2165_upload_firmware_block(state, data, len,
  offset, block_count);
 
Good catch.

Signed-off-by: Matthias Schwarzott z...@gentoo.org

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


Re: [PATCH] cx23885: Split Hauppauge WinTV Starburst from HVR4400 card entry

2014-12-22 Thread Matthias Schwarzott
On 22.12.2014 13:59, Steven Toth wrote:
 On Sun, Dec 21, 2014 at 2:59 PM, Matthias Schwarzott z...@gentoo.org wrote:
 Unconditionally attaching Si2161/Si2165 demod driver
 breaks Hauppauge WinTV Starburst.
 So create own card entry for this.

 Add card name comments to the subsystem ids.

 Signed-off-by: Matthias Schwarzott z...@gentoo.org
 
 Matthias,
 
 Thank you for your work. However, nobody knows or cares what
 'STARBURST' is. When I created the original driver I was careful to
 name the card identified to match the actual hardware names that were
 sold in retail, this eases future maintenance for people with no
 knowledge of the hardware and makes Linux support for the HVR550 much
 more obvious in google.
 
 Please change CX23885_BOARD_HAUPPAUGE_STARBURST to
 CX23885_BOARD_HAUPPAUGE_HVR5500.
 
 Thanks,
 
Hi Steven,

thank you for your feedback.

I rechecked the names and this are the more or less supported devices:
* Starburst supports DVB-S2 only
* HVR-4400 supports DVB-S2 + DVB-T (Si2161)
* HVR-5500 supports DVB-S2 + DVB-C/T (Si2165)

As starburst has only one demod and HVR-4400/HVR-5500 have two, there is
one card entry for HVR-4400/HVR-5500 and a second one with different
name for the Sturburst.

Checking hauppauge homepage I directly get to the WinTV-Starburst:
http://www.hauppauge.de/site/products/data_starburst.html

So I see this is an official product name. Why not show this name?

Regards
Matthias

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


Re: [PATCH] cx23885: Split Hauppauge WinTV Starburst from HVR4400 card entry

2014-12-22 Thread Matthias Schwarzott
On 22.12.2014 14:25, Mauro Carvalho Chehab wrote:
 Em Sun, 21 Dec 2014 21:07:02 +0100
 Matthias Schwarzott z...@gentoo.org escreveu:
 
 Hi!

 Should the commit message directly point to the breaking commit
 36efec48e2e6016e05364906720a0ec350a5d768?
 
 Yes, if this fixes an issue that happened on a previous commit, then
 you should add the original commit there.
 
 That likely means that this is a regression fix, right? So, you should
 c/c the patch to stable, adding a comment msg telling to what Kernel
 version it applies (assuming that the patch was merged on 3.18).
 Also, please add PATCH FIX to the subject, as this patch should be
 sent to 3.19 as well.
 

 This commit hopefully reverts the problematic attach for the Starburst
 card. I kept the GPIO-part in common, but I can split this also if
 necessary.
 
 Keep the GPIO part in common is better, if the GPIOs are the same.

Hi!

The GPIO-Pins that are used are the same on both cards. And I assume the
ones that control Si2165 on HVR-5500 are just unused on Starburst, so
setting them does not hurt (and Antti confirmed that the patch works).

The cards have more in common, but I could not find a clean way to share
attaching and TS-config of the DVB-S2 frontend.

So I will change the commit message, prefix subject with PATCH fix, and
resend the patch here and c/c to stable.

Regards
Matthias

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


[PATCH] cx23885: Split Hauppauge WinTV Starburst from HVR4400 card entry

2014-12-22 Thread Matthias Schwarzott
Unconditionally attaching Si2161/Si2165 demod driver
breaks Hauppauge WinTV Starburst.
So create own card entry for this.

Add card name comments to the subsystem ids.

This fixes a regression introduced in 3.17 by
36efec48e2e6016e05364906720a0ec350a5d768 ([media] cx23885: Add si2165 support 
for HVR-5500)

Signed-off-by: Matthias Schwarzott z...@gentoo.org
Tested-by: Antti Palosaari cr...@iki.fi
---
 Only the commit message has been changed since last posting.

 The stable patches will be sent seperately against v3.17 and v3.18.

 drivers/media/pci/cx23885/cx23885-cards.c | 23 +--
 drivers/media/pci/cx23885/cx23885-dvb.c   | 11 +++
 drivers/media/pci/cx23885/cx23885.h   |  1 +
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/drivers/media/pci/cx23885/cx23885-cards.c 
b/drivers/media/pci/cx23885/cx23885-cards.c
index db99ca2..06931f6 100644
--- a/drivers/media/pci/cx23885/cx23885-cards.c
+++ b/drivers/media/pci/cx23885/cx23885-cards.c
@@ -614,7 +614,7 @@ struct cx23885_board cx23885_boards[] = {
.portb  = CX23885_MPEG_DVB,
},
[CX23885_BOARD_HAUPPAUGE_HVR4400] = {
-   .name   = Hauppauge WinTV-HVR4400,
+   .name   = Hauppauge WinTV-HVR4400/HVR5500,
.porta  = CX23885_ANALOG_VIDEO,
.portb  = CX23885_MPEG_DVB,
.portc  = CX23885_MPEG_DVB,
@@ -622,6 +622,10 @@ struct cx23885_board cx23885_boards[] = {
.tuner_addr = 0x60, /* 0xc0  1 */
.tuner_bus  = 1,
},
+   [CX23885_BOARD_HAUPPAUGE_STARBURST] = {
+   .name   = Hauppauge WinTV Starburst,
+   .portb  = CX23885_MPEG_DVB,
+   },
[CX23885_BOARD_AVERMEDIA_HC81R] = {
.name   = AVerTV Hybrid Express Slim HC81R,
.tuner_type = TUNER_XC2028,
@@ -936,19 +940,19 @@ struct cx23885_subid cx23885_subids[] = {
}, {
.subvendor = 0x0070,
.subdevice = 0xc108,
-   .card  = CX23885_BOARD_HAUPPAUGE_HVR4400,
+   .card  = CX23885_BOARD_HAUPPAUGE_HVR4400, /* Hauppauge 
WinTV HVR-4400 (Model 121xxx, Hybrid DVB-T/S2, IR) */
}, {
.subvendor = 0x0070,
.subdevice = 0xc138,
-   .card  = CX23885_BOARD_HAUPPAUGE_HVR4400,
+   .card  = CX23885_BOARD_HAUPPAUGE_HVR4400, /* Hauppauge 
WinTV HVR-5500 (Model 121xxx, Hybrid DVB-T/C/S2, IR) */
}, {
.subvendor = 0x0070,
.subdevice = 0xc12a,
-   .card  = CX23885_BOARD_HAUPPAUGE_HVR4400,
+   .card  = CX23885_BOARD_HAUPPAUGE_STARBURST, /* Hauppauge 
WinTV Starburst (Model 121x00, DVB-S2, IR) */
}, {
.subvendor = 0x0070,
.subdevice = 0xc1f8,
-   .card  = CX23885_BOARD_HAUPPAUGE_HVR4400,
+   .card  = CX23885_BOARD_HAUPPAUGE_HVR4400, /* Hauppauge 
WinTV HVR-5500 (Model 121xxx, Hybrid DVB-T/C/S2, IR) */
}, {
.subvendor = 0x1461,
.subdevice = 0xd939,
@@ -1545,8 +1549,9 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
cx_write(GPIO_ISM, 0x);/* INTERRUPTS active low*/
break;
case CX23885_BOARD_HAUPPAUGE_HVR4400:
+   case CX23885_BOARD_HAUPPAUGE_STARBURST:
/* GPIO-8 tda10071 demod reset */
-   /* GPIO-9 si2165 demod reset */
+   /* GPIO-9 si2165 demod reset (only HVR4400/HVR5500)*/
 
/* Put the parts into reset and back */
cx23885_gpio_enable(dev, GPIO_8 | GPIO_9, 1);
@@ -1872,6 +1877,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
case CX23885_BOARD_HAUPPAUGE_HVR1850:
case CX23885_BOARD_HAUPPAUGE_HVR1290:
case CX23885_BOARD_HAUPPAUGE_HVR4400:
+   case CX23885_BOARD_HAUPPAUGE_STARBURST:
case CX23885_BOARD_HAUPPAUGE_IMPACTVCBE:
if (dev-i2c_bus[0].i2c_rc == 0)
hauppauge_eeprom(dev, eeprom+0xc0);
@@ -1980,6 +1986,11 @@ void cx23885_card_setup(struct cx23885_dev *dev)
ts2-ts_clk_en_val = 0x1; /* Enable TS_CLK */
ts2-src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
break;
+   case CX23885_BOARD_HAUPPAUGE_STARBURST:
+   ts1-gen_ctrl_val  = 0xc; /* Serial bus + punctured clock */
+   ts1-ts_clk_en_val = 0x1; /* Enable TS_CLK */
+   ts1-src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
+   break;
case CX23885_BOARD_DVBSKY_T9580:
case CX23885_BOARD_DVBSKY_T982:
ts1-gen_ctrl_val  = 0x5; /* Parallel */
diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c 
b/drivers/media/pci/cx23885/cx23885-dvb.c
index c47d182..a9c450d 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c

Re: cx23885: Add si2165 support for HVR-5500

2014-12-21 Thread Matthias Schwarzott
On 20.12.2014 16:31, Antti Palosaari wrote:
 Matthias and Mauro,
Hi Antti,
meanwhile HVR-4400 has been tested by multiple people. And it works
rather good for DVB-T.

 so you decided to add that patch, which makes rather big changes for
 existing HVR-4400 models, without any testing. I plugged HVR-4400
 version that has only DVB-S2 in my machine in order to start finding out
 one lockdep issue but what I see is bad HVR-4400.

I checked that all known HVR-4400 and HVR-5500 versions have a
Si2161/Si2165 chip.

I checked your subsystem id 0070:c12a. In windows inf file it is listed
as Hauppauge WinTV Starburst (Model 121x00, DVB-S2, IR).
But this subsystem id is also part of the HVR-4400 entry (as is HVR-5500).

So I rechecked the HVR4400 entry.
It points to these subsys ids (plus description from inf file):
* 0070:c108 Hauppauge WinTV HVR-4400 (Model 121xxx, Hybrid DVB-T/S2, IR)
* 0070:c138 Hauppauge WinTV HVR-5500 (Model 121xxx, Hybrid DVB-T/C/S2, IR)
* 0070:c1f8 Hauppauge WinTV HVR-5500 (Model 121xxx, Hybrid DVB-T/C/S2, IR)
* 0070:c12a Hauppauge WinTV Starburst (Model 121x00, DVB-S2, IR)

 
 I would also criticize Mauro as he has committed that patch. It should
 be obvious for every experienced media developer that this kind of not
 trivial change needs some more careful review or testing.
 
 That patch should be done differently, not blindly trying to attach chip
 drivers for non-existent chips. I think correct solution is to detect
 different HW models somehow, probing or reading from eeprom or so. Then
 make 2 profiles, one for boards having both satellite and
 terristrial/cable and one for boards having satellite only.
 
As can be seen above it should be possible to decide by checking the
subsys id.
So having two board entries should be the best solution.
One for HVR-4400/HVR-5500 and the other for the Starburst.

Regards
Matthias


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


[PATCH] cx23885: Split Hauppauge WinTV Starburst from HVR4400 card entry

2014-12-21 Thread Matthias Schwarzott
Unconditionally attaching Si2161/Si2165 demod driver
breaks Hauppauge WinTV Starburst.
So create own card entry for this.

Add card name comments to the subsystem ids.

Signed-off-by: Matthias Schwarzott z...@gentoo.org
---
 drivers/media/pci/cx23885/cx23885-cards.c | 23 +--
 drivers/media/pci/cx23885/cx23885-dvb.c   | 11 +++
 drivers/media/pci/cx23885/cx23885.h   |  1 +
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/drivers/media/pci/cx23885/cx23885-cards.c 
b/drivers/media/pci/cx23885/cx23885-cards.c
index db99ca2..06931f6 100644
--- a/drivers/media/pci/cx23885/cx23885-cards.c
+++ b/drivers/media/pci/cx23885/cx23885-cards.c
@@ -614,7 +614,7 @@ struct cx23885_board cx23885_boards[] = {
.portb  = CX23885_MPEG_DVB,
},
[CX23885_BOARD_HAUPPAUGE_HVR4400] = {
-   .name   = Hauppauge WinTV-HVR4400,
+   .name   = Hauppauge WinTV-HVR4400/HVR5500,
.porta  = CX23885_ANALOG_VIDEO,
.portb  = CX23885_MPEG_DVB,
.portc  = CX23885_MPEG_DVB,
@@ -622,6 +622,10 @@ struct cx23885_board cx23885_boards[] = {
.tuner_addr = 0x60, /* 0xc0  1 */
.tuner_bus  = 1,
},
+   [CX23885_BOARD_HAUPPAUGE_STARBURST] = {
+   .name   = Hauppauge WinTV Starburst,
+   .portb  = CX23885_MPEG_DVB,
+   },
[CX23885_BOARD_AVERMEDIA_HC81R] = {
.name   = AVerTV Hybrid Express Slim HC81R,
.tuner_type = TUNER_XC2028,
@@ -936,19 +940,19 @@ struct cx23885_subid cx23885_subids[] = {
}, {
.subvendor = 0x0070,
.subdevice = 0xc108,
-   .card  = CX23885_BOARD_HAUPPAUGE_HVR4400,
+   .card  = CX23885_BOARD_HAUPPAUGE_HVR4400, /* Hauppauge 
WinTV HVR-4400 (Model 121xxx, Hybrid DVB-T/S2, IR) */
}, {
.subvendor = 0x0070,
.subdevice = 0xc138,
-   .card  = CX23885_BOARD_HAUPPAUGE_HVR4400,
+   .card  = CX23885_BOARD_HAUPPAUGE_HVR4400, /* Hauppauge 
WinTV HVR-5500 (Model 121xxx, Hybrid DVB-T/C/S2, IR) */
}, {
.subvendor = 0x0070,
.subdevice = 0xc12a,
-   .card  = CX23885_BOARD_HAUPPAUGE_HVR4400,
+   .card  = CX23885_BOARD_HAUPPAUGE_STARBURST, /* Hauppauge 
WinTV Starburst (Model 121x00, DVB-S2, IR) */
}, {
.subvendor = 0x0070,
.subdevice = 0xc1f8,
-   .card  = CX23885_BOARD_HAUPPAUGE_HVR4400,
+   .card  = CX23885_BOARD_HAUPPAUGE_HVR4400, /* Hauppauge 
WinTV HVR-5500 (Model 121xxx, Hybrid DVB-T/C/S2, IR) */
}, {
.subvendor = 0x1461,
.subdevice = 0xd939,
@@ -1545,8 +1549,9 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
cx_write(GPIO_ISM, 0x);/* INTERRUPTS active low*/
break;
case CX23885_BOARD_HAUPPAUGE_HVR4400:
+   case CX23885_BOARD_HAUPPAUGE_STARBURST:
/* GPIO-8 tda10071 demod reset */
-   /* GPIO-9 si2165 demod reset */
+   /* GPIO-9 si2165 demod reset (only HVR4400/HVR5500)*/
 
/* Put the parts into reset and back */
cx23885_gpio_enable(dev, GPIO_8 | GPIO_9, 1);
@@ -1872,6 +1877,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
case CX23885_BOARD_HAUPPAUGE_HVR1850:
case CX23885_BOARD_HAUPPAUGE_HVR1290:
case CX23885_BOARD_HAUPPAUGE_HVR4400:
+   case CX23885_BOARD_HAUPPAUGE_STARBURST:
case CX23885_BOARD_HAUPPAUGE_IMPACTVCBE:
if (dev-i2c_bus[0].i2c_rc == 0)
hauppauge_eeprom(dev, eeprom+0xc0);
@@ -1980,6 +1986,11 @@ void cx23885_card_setup(struct cx23885_dev *dev)
ts2-ts_clk_en_val = 0x1; /* Enable TS_CLK */
ts2-src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
break;
+   case CX23885_BOARD_HAUPPAUGE_STARBURST:
+   ts1-gen_ctrl_val  = 0xc; /* Serial bus + punctured clock */
+   ts1-ts_clk_en_val = 0x1; /* Enable TS_CLK */
+   ts1-src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
+   break;
case CX23885_BOARD_DVBSKY_T9580:
case CX23885_BOARD_DVBSKY_T982:
ts1-gen_ctrl_val  = 0x5; /* Parallel */
diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c 
b/drivers/media/pci/cx23885/cx23885-dvb.c
index c47d182..a9c450d 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -1710,6 +1710,17 @@ static int dvb_register(struct cx23885_tsport *port)
break;
}
break;
+   case CX23885_BOARD_HAUPPAUGE_STARBURST:
+   i2c_bus = dev-i2c_bus[0];
+   fe0

Re: [PATCH] cx23885: Split Hauppauge WinTV Starburst from HVR4400 card entry

2014-12-21 Thread Matthias Schwarzott
Hi!

Should the commit message directly point to the breaking commit
36efec48e2e6016e05364906720a0ec350a5d768?

This commit hopefully reverts the problematic attach for the Starburst
card. I kept the GPIO-part in common, but I can split this also if
necessary.

Regards
Matthias

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


Re: [PATCH 6/7] [media] cx231xx-i2c: fix i2c_scan modprobe parameter

2014-11-01 Thread Matthias Schwarzott
On 01.11.2014 14:38, Mauro Carvalho Chehab wrote:
 This device doesn't properly implement read with a zero bytes
 len. So, use 1 byte for I2C scan.
 
Yes, the idea sounds good, but we should fix this in the code in
cx231xx_i2c_check_for_device.

 Signed-off-by: Mauro Carvalho Chehab mche...@osg.samsung.com
 
 diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c 
 b/drivers/media/usb/cx231xx/cx231xx-i2c.c
 index 1a0d9efeb209..9b7e5a155e34 100644
 --- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
 +++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
 @@ -502,7 +502,7 @@ void cx231xx_do_i2c_scan(struct cx231xx *dev, int 
 i2c_port)
   i2c_port);
   for (i = 0; i  128; i++) {
   client.addr = i;
 - rc = i2c_master_recv(client, buf, 0);
 + rc = i2c_master_recv(client, buf, 1);
   if (rc  0)
   continue;
   pr_info(i2c scan: found device @ 0x%x  [%s]\n,
 

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


[PATCH] cx231xx: use 1 byte read for i2c scan

2014-11-01 Thread Matthias Schwarzott
Now cx231xx_i2c_check_for_device works like i2c_check_for_device of em28xx 
driver.

For me this fixes scanning of all ports but port 2.

Signed-off-by: Matthias Schwarzott z...@gentoo.org
---
 drivers/media/usb/cx231xx/cx231xx-i2c.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c 
b/drivers/media/usb/cx231xx/cx231xx-i2c.c
index d1003c7..fe17a13 100644
--- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
@@ -350,14 +350,15 @@ static int cx231xx_i2c_check_for_device(struct 
i2c_adapter *i2c_adap,
struct cx231xx *dev = bus-dev;
struct cx231xx_i2c_xfer_data req_data;
int status = 0;
+   u8 buf[1];
 
/* prepare xfer_data struct */
req_data.dev_addr = msg-addr;
-   req_data.direction = msg-flags;
+   req_data.direction = I2C_M_RD;
req_data.saddr_len = 0;
req_data.saddr_dat = 0;
-   req_data.buf_size = 0;
-   req_data.p_buffer = NULL;
+   req_data.buf_size = 1;
+   req_data.p_buffer = buf;
 
/* usb send command */
status = dev-cx231xx_send_usb_command(bus, req_data);
-- 
2.1.3

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


[PATCH] tveeprom: Update list of chips and extend serial number to 32bits

2014-10-31 Thread Matthias Schwarzott
The update was supplied directly by PCTV.

Add tuner ids 182-188.
Add audproc ids 45-52.
Add decoder chip ids 43-53.
Use 32bits for the serial number.

Signed-off-by: Matthias Schwarzott z...@gentoo.org
---
 drivers/media/common/tveeprom.c | 36 +---
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/drivers/media/common/tveeprom.c b/drivers/media/common/tveeprom.c
index c7dace6..47da037 100644
--- a/drivers/media/common/tveeprom.c
+++ b/drivers/media/common/tveeprom.c
@@ -286,9 +286,17 @@ static const struct {
{ TUNER_ABSENT, Xceive XC5200C},
{ TUNER_ABSENT, NXP 18273},
{ TUNER_ABSENT, Montage M88TS2022},
-   /* 180-189 */
+   /* 180-188 */
{ TUNER_ABSENT, NXP 18272M},
{ TUNER_ABSENT, NXP 18272S},
+
+   { TUNER_ABSENT, Mirics MSi003},
+   { TUNER_ABSENT, MaxLinear MxL256},
+   { TUNER_ABSENT, SiLabs Si2158},
+   { TUNER_ABSENT, SiLabs Si2178},
+   { TUNER_ABSENT, SiLabs Si2157},
+   { TUNER_ABSENT, SiLabs Si2177},
+   { TUNER_ABSENT, ITE IT9137FN},
 };
 
 /* Use TVEEPROM_AUDPROC_INTERNAL for those audio 'chips' that are
@@ -351,6 +359,16 @@ static const struct {
{ TVEEPROM_AUDPROC_INTERNAL, CX23887   },
{ TVEEPROM_AUDPROC_INTERNAL, SAA7164   },
{ TVEEPROM_AUDPROC_INTERNAL, AU8522},
+   /* 45-49 */
+   { TVEEPROM_AUDPROC_INTERNAL, AVF4910B  },
+   { TVEEPROM_AUDPROC_INTERNAL, SAA7231   },
+   { TVEEPROM_AUDPROC_INTERNAL, CX23102   },
+   { TVEEPROM_AUDPROC_INTERNAL, SAA7163   },
+   { TVEEPROM_AUDPROC_OTHER,AK4113},
+   /* 50-52 */
+   { TVEEPROM_AUDPROC_OTHER,CS5340},
+   { TVEEPROM_AUDPROC_OTHER,CS8416},
+   { TVEEPROM_AUDPROC_OTHER,CX20810   },
 };
 
 /* This list is supplied by Hauppauge. Thanks! */
@@ -371,8 +389,12 @@ static const char *decoderIC[] = {
CX25843, CX23418, NEC61153, CX23885, CX23888,
/* 35-39 */
SAA7131, CX25837, CX23887, CX23885A, CX23887A,
-   /* 40-42 */
-   SAA7164, CX23885B, AU8522
+   /* 40-44 */
+   SAA7164, CX23885B, AU8522, ADV7401, AVF4910B,
+   /* 45-49 */
+   SAA7231, CX23102, SAA7163, ADV7441A, ADV7181C,
+   /* 50-53 */
+   CX25836, TDA9955, TDA19977, ADV7842
 };
 
 static int hasRadioTuner(int tunerType)
@@ -548,10 +570,10 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, 
struct tveeprom *tvee,
tvee-serial_number =
eeprom_data[i+5] +
(eeprom_data[i+6]  8) +
-   (eeprom_data[i+7]  16);
+   (eeprom_data[i+7]  16)+
+   (eeprom_data[i+8]  24);
 
-   if ((eeprom_data[i + 8]  0xf0) 
-   (tvee-serial_number  0xff)) {
+   if (eeprom_data[i + 8] == 0xf0) {
tvee-MAC_address[0] = 0x00;
tvee-MAC_address[1] = 0x0D;
tvee-MAC_address[2] = 0xFE;
@@ -696,7 +718,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct 
tveeprom *tvee,
}
}
 
-   tveeprom_info(Hauppauge model %d, rev %s, serial# %d\n,
+   tveeprom_info(Hauppauge model %d, rev %s, serial# %u\n,
tvee-model, tvee-rev_str, tvee-serial_number);
if (tvee-has_MAC_address == 1)
tveeprom_info(MAC address is %pM\n, tvee-MAC_address);
-- 
2.1.2

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


Re: [PATCH] cx231xx: remove direct register PWR_CTL_EN modification that switches port3

2014-10-31 Thread Matthias Schwarzott
On 31.10.2014 11:32, Mauro Carvalho Chehab wrote:
 Em Thu, 30 Oct 2014 23:43:55 +0100
 Matthias Schwarzott z...@gentoo.org escreveu:
 
 The only remaining place that modifies the relevant bit is in function
 cx231xx_set_Colibri_For_LowIF

 Signed-off-by: Matthias Schwarzott z...@gentoo.org
 ---
  drivers/media/usb/cx231xx/cx231xx-avcore.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

 diff --git a/drivers/media/usb/cx231xx/cx231xx-avcore.c 
 b/drivers/media/usb/cx231xx/cx231xx-avcore.c
 index b56bc87..781908b 100644
 --- a/drivers/media/usb/cx231xx/cx231xx-avcore.c
 +++ b/drivers/media/usb/cx231xx/cx231xx-avcore.c
 @@ -2270,7 +2270,6 @@ int cx231xx_set_power_mode(struct cx231xx *dev, enum 
 AV_MODE mode)
  case POLARIS_AVMODE_ANALOGT_TV:
  
  tmp |= PWR_DEMOD_EN;
 -tmp |= (I2C_DEMOD_EN);
  value[0] = (u8) tmp;
  value[1] = (u8) (tmp  8);
  value[2] = (u8) (tmp  16);
 @@ -2366,7 +2365,7 @@ int cx231xx_set_power_mode(struct cx231xx *dev, enum 
 AV_MODE mode)
  }
  
  tmp = (~PWR_AV_MODE);
 -tmp |= POLARIS_AVMODE_DIGITAL | I2C_DEMOD_EN;
 +tmp |= POLARIS_AVMODE_DIGITAL;
  value[0] = (u8) tmp;
  value[1] = (u8) (tmp  8);
  value[2] = (u8) (tmp  16);
 

Hi Mauro,

 Hmm... Not sure if this patch is right. There is one I2C bus internally
 at cx231xx. Some configurations need to go through this I2C bus. 
 

What exactly do you mean by configurations need to go through this I2C
bus? Do you mean the port3 switch must have a specific value even when
not doing i2c transfers?

 Did you test if changing from/to analog/digital mode is working?
 

I did not yet check analog mode.

Regards
Matthias

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


[PATCH v4 00/14] cx231xx: Use muxed i2c adapters instead of custom switching

2014-10-30 Thread Matthias Schwarzott
Hi!

This time the series got only small updates from Antti's review.

Additionally I added a patch to no longer directly modify
the content of the port3 switch bit in PWR_CTL_EN (from function 
cx231xx_set_power_mode).

Now there are two places where I wonder what happens:
1. cx231xx_set_Colibri_For_LowIF writes a fixed number into all 8bit parts of 
PWR_CTL_EN
   What is this for?
2. I guess, cx231xx_demod_reset should reset the digital demod. For this it 
should toggle the bits 0 and 1 of PWR_CTL_EN. 
   But instead it touches but 8 and 9.
   Does someone know what this is?

3. Is remembering the last status of the port3 bit working good enough?
   Currently it is only used for the is_tuner hack function.

Regards
Matthias

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


[PATCH v4 02/14] cx231xx: use own i2c_client for eeprom access

2014-10-30 Thread Matthias Schwarzott
This is a preparation for deleting the otherwise useless i2c_clients
that are allocated for all the i2c master adapters.

Signed-off-by: Matthias Schwarzott z...@gentoo.org
Reviewed-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/cx231xx/cx231xx-cards.c | 24 +---
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c 
b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 791f00c..092fb85 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -980,23 +980,20 @@ static void cx231xx_config_tuner(struct cx231xx *dev)
 
 }
 
-static int read_eeprom(struct cx231xx *dev, u8 *eedata, int len)
+static int read_eeprom(struct cx231xx *dev, struct i2c_client *client,
+  u8 *eedata, int len)
 {
int ret = 0;
-   u8 addr = 0xa0  1;
u8 start_offset = 0;
int len_todo = len;
u8 *eedata_cur = eedata;
int i;
-   struct i2c_msg msg_write = { .addr = addr, .flags = 0,
+   struct i2c_msg msg_write = { .addr = client-addr, .flags = 0,
.buf = start_offset, .len = 1 };
-   struct i2c_msg msg_read = { .addr = addr, .flags = I2C_M_RD };
-
-   /* mutex_lock(dev-i2c_lock); */
-   cx231xx_enable_i2c_port_3(dev, false);
+   struct i2c_msg msg_read = { .addr = client-addr, .flags = I2C_M_RD };
 
/* start reading at offset 0 */
-   ret = i2c_transfer(dev-i2c_bus[1].i2c_adap, msg_write, 1);
+   ret = i2c_transfer(client-adapter, msg_write, 1);
if (ret  0) {
cx231xx_err(Can't read eeprom\n);
return ret;
@@ -1006,7 +1003,7 @@ static int read_eeprom(struct cx231xx *dev, u8 *eedata, 
int len)
msg_read.len = (len_todo  64) ? 64 : len_todo;
msg_read.buf = eedata_cur;
 
-   ret = i2c_transfer(dev-i2c_bus[1].i2c_adap, msg_read, 1);
+   ret = i2c_transfer(client-adapter, msg_read, 1);
if (ret  0) {
cx231xx_err(Can't read eeprom\n);
return ret;
@@ -1062,9 +1059,14 @@ void cx231xx_card_setup(struct cx231xx *dev)
{
struct tveeprom tvee;
static u8 eeprom[256];
+   struct i2c_client client;
+
+   memset(client, 0, sizeof(client));
+   client.adapter = dev-i2c_bus[1].i2c_adap;
+   client.addr = 0xa0  1;
 
-   read_eeprom(dev, eeprom, sizeof(eeprom));
-   tveeprom_hauppauge_analog(dev-i2c_bus[1].i2c_client,
+   read_eeprom(dev, client, eeprom, sizeof(eeprom));
+   tveeprom_hauppauge_analog(client,
tvee, eeprom + 0xc0);
break;
}
-- 
2.1.2

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


[PATCH v4 03/14] cx231xx: delete i2c_client per bus

2014-10-30 Thread Matthias Schwarzott
For each i2c master there is a i2c_client allocated that could be
deleted now that its only two users have been changed to use their
own i2c_client.

Signed-off-by: Matthias Schwarzott z...@gentoo.org
Reviewed-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/cx231xx/cx231xx-i2c.c | 7 ---
 drivers/media/usb/cx231xx/cx231xx.h | 1 -
 2 files changed, 8 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c 
b/drivers/media/usb/cx231xx/cx231xx-i2c.c
index 67a1391..a30d400 100644
--- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
@@ -455,10 +455,6 @@ static struct i2c_adapter cx231xx_adap_template = {
.algo = cx231xx_algo,
 };
 
-static struct i2c_client cx231xx_client_template = {
-   .name = cx231xx internal,
-};
-
 /* --- */
 
 /*
@@ -514,7 +510,6 @@ int cx231xx_i2c_register(struct cx231xx_i2c *bus)
BUG_ON(!dev-cx231xx_send_usb_command);
 
bus-i2c_adap = cx231xx_adap_template;
-   bus-i2c_client = cx231xx_client_template;
bus-i2c_adap.dev.parent = dev-udev-dev;
 
strlcpy(bus-i2c_adap.name, bus-dev-name, sizeof(bus-i2c_adap.name));
@@ -523,8 +518,6 @@ int cx231xx_i2c_register(struct cx231xx_i2c *bus)
i2c_set_adapdata(bus-i2c_adap, dev-v4l2_dev);
i2c_add_adapter(bus-i2c_adap);
 
-   bus-i2c_client.adapter = bus-i2c_adap;
-
if (0 == bus-i2c_rc) {
if (i2c_scan)
cx231xx_do_i2c_scan(dev, bus-nr);
diff --git a/drivers/media/usb/cx231xx/cx231xx.h 
b/drivers/media/usb/cx231xx/cx231xx.h
index 5efc93e..c92382f 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -472,7 +472,6 @@ struct cx231xx_i2c {
 
/* i2c i/o */
struct i2c_adapter i2c_adap;
-   struct i2c_client i2c_client;
u32 i2c_rc;
 
/* different settings for each bus */
-- 
2.1.2

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


[PATCH v4 12/14] cx231xx: remove direct register PWR_CTL_EN modification that switches port3

2014-10-30 Thread Matthias Schwarzott
The only remaining place that modifies the relevant bit is in function
cx231xx_set_Colibri_For_LowIF

Signed-off-by: Matthias Schwarzott z...@gentoo.org
---
 drivers/media/usb/cx231xx/cx231xx-avcore.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-avcore.c 
b/drivers/media/usb/cx231xx/cx231xx-avcore.c
index 0a5fec4..a3e4915 100644
--- a/drivers/media/usb/cx231xx/cx231xx-avcore.c
+++ b/drivers/media/usb/cx231xx/cx231xx-avcore.c
@@ -2276,7 +2276,6 @@ int cx231xx_set_power_mode(struct cx231xx *dev, enum 
AV_MODE mode)
case POLARIS_AVMODE_ANALOGT_TV:
 
tmp |= PWR_DEMOD_EN;
-   tmp |= (I2C_DEMOD_EN);
value[0] = (u8) tmp;
value[1] = (u8) (tmp  8);
value[2] = (u8) (tmp  16);
@@ -2375,7 +2374,7 @@ int cx231xx_set_power_mode(struct cx231xx *dev, enum 
AV_MODE mode)
}
 
tmp = (~PWR_AV_MODE);
-   tmp |= POLARIS_AVMODE_DIGITAL | I2C_DEMOD_EN;
+   tmp |= POLARIS_AVMODE_DIGITAL;
value[0] = (u8) tmp;
value[1] = (u8) (tmp  8);
value[2] = (u8) (tmp  16);
-- 
2.1.2

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


[PATCH v4 13/14] cx231xx: drop unconditional port3 switching

2014-10-30 Thread Matthias Schwarzott
All switching should be done by i2c mux adapters.
Drop explicit dont_use_port_3 flag.
Drop info message about switch.

Only the removed code in start_streaming is questionable:
It did switch the port_3 flag without accessing i2c in between.

Signed-off-by: Matthias Schwarzott z...@gentoo.org
Reviewed-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/cx231xx/cx231xx-avcore.c | 18 --
 drivers/media/usb/cx231xx/cx231xx-cards.c  |  8 
 drivers/media/usb/cx231xx/cx231xx-core.c   |  4 +---
 drivers/media/usb/cx231xx/cx231xx-dvb.c|  4 
 drivers/media/usb/cx231xx/cx231xx.h|  1 -
 5 files changed, 1 insertion(+), 34 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-avcore.c 
b/drivers/media/usb/cx231xx/cx231xx-avcore.c
index a3e4915..781908b 100644
--- a/drivers/media/usb/cx231xx/cx231xx-avcore.c
+++ b/drivers/media/usb/cx231xx/cx231xx-avcore.c
@@ -1270,9 +1270,6 @@ int cx231xx_enable_i2c_port_3(struct cx231xx *dev, bool 
is_port_3)
int status = 0;
bool current_is_port_3;
 
-   if (dev-board.dont_use_port_3)
-   is_port_3 = false;
-
/*
 * Should this code check dev-port_3_switch_enabled first
 * to skip unnecessary reading of the register?
@@ -1296,9 +1293,6 @@ int cx231xx_enable_i2c_port_3(struct cx231xx *dev, bool 
is_port_3)
else
value[0] = ~I2C_DEMOD_EN;
 
-   cx231xx_info(Changing the i2c master port to %d\n,
-is_port_3 ?  3 : 1);
-
status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
PWR_CTL_EN, value, 4);
 
@@ -2328,9 +2322,6 @@ int cx231xx_set_power_mode(struct cx231xx *dev, enum 
AV_MODE mode)
}
 
if (dev-board.tuner_type != TUNER_ABSENT) {
-   /* Enable tuner */
-   cx231xx_enable_i2c_port_3(dev, true);
-
/* reset the Tuner */
if (dev-board.tuner_gpio)
cx231xx_gpio_set(dev, dev-board.tuner_gpio);
@@ -2395,15 +2386,6 @@ int cx231xx_set_power_mode(struct cx231xx *dev, enum 
AV_MODE mode)
}
 
if (dev-board.tuner_type != TUNER_ABSENT) {
-   /*
-* Enable tuner
-*  Hauppauge Exeter seems to need to do something 
different!
-*/
-   if (dev-model == CX231XX_BOARD_HAUPPAUGE_EXETER)
-   cx231xx_enable_i2c_port_3(dev, false);
-   else
-   cx231xx_enable_i2c_port_3(dev, true);
-
/* reset the Tuner */
if (dev-board.tuner_gpio)
cx231xx_gpio_set(dev, dev-board.tuner_gpio);
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c 
b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 4eb2057..432cbcf 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -262,7 +262,6 @@ struct cx231xx_board cx231xx_boards[] = {
.norm = V4L2_STD_PAL,
.no_alt_vanc = 1,
.external_av = 1,
-   .dont_use_port_3 = 1,
/* Actually, it has a 417, but it isn't working correctly.
 * So set to 0 for now until someone can manage to get this
 * to work reliably. */
@@ -390,7 +389,6 @@ struct cx231xx_board cx231xx_boards[] = {
.norm = V4L2_STD_NTSC,
.no_alt_vanc = 1,
.external_av = 1,
-   .dont_use_port_3 = 1,
.input = {{
.type = CX231XX_VMUX_COMPOSITE1,
.vmux = CX231XX_VIN_2_1,
@@ -532,7 +530,6 @@ struct cx231xx_board cx231xx_boards[] = {
.norm = V4L2_STD_NTSC,
.no_alt_vanc = 1,
.external_av = 1,
-   .dont_use_port_3 = 1,
 
.input = {{
.type = CX231XX_VMUX_COMPOSITE1,
@@ -656,7 +653,6 @@ struct cx231xx_board cx231xx_boards[] = {
.norm = V4L2_STD_NTSC,
.no_alt_vanc = 1,
.external_av = 1,
-   .dont_use_port_3 = 1,
.input = {{
.type = CX231XX_VMUX_COMPOSITE1,
.vmux = CX231XX_VIN_2_1,
@@ -683,7 +679,6 @@ struct cx231xx_board cx231xx_boards[] = {
.norm = V4L2_STD_NTSC,
.no_alt_vanc = 1,
.external_av = 1,
-   .dont_use_port_3 = 1,
/*.has_417 = 1, */
/* This board is believed to have a hardware encoding chip
 * supporting mpeg1/2/4, but as the 417 is apparently not
@@ -1012,9 +1007,6 @@ static int read_eeprom(struct cx231xx *dev, struct 
i2c_client *client,
len_todo -= msg_read.len

[PATCH v4 07/14] cx231xx: add wrapper to get the i2c_adapter pointer

2014-10-30 Thread Matthias Schwarzott
This is a preparation for mapping I2C_1_MUX_1 and I2C_1_MUX_3 later to the 
seperate
muxed i2c adapters.

Map mux adapters to I2C_1 for now.

Add local variables for i2c_adapters in dvb_init to get line lengths
shorter.

Signed-off-by: Matthias Schwarzott z...@gentoo.org
Reviewed-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/cx231xx/cx231xx-cards.c |  8 +++---
 drivers/media/usb/cx231xx/cx231xx-dvb.c   | 42 +--
 drivers/media/usb/cx231xx/cx231xx-i2c.c   | 20 ++-
 drivers/media/usb/cx231xx/cx231xx-input.c |  3 ++-
 drivers/media/usb/cx231xx/cx231xx.h   |  1 +
 5 files changed, 50 insertions(+), 24 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c 
b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 2f027c7..f5fb93a 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1033,7 +1033,7 @@ void cx231xx_card_setup(struct cx231xx *dev)
/* request some modules */
if (dev-board.decoder == CX231XX_AVDECODER) {
dev-sd_cx25840 = v4l2_i2c_new_subdev(dev-v4l2_dev,
-   dev-i2c_bus[I2C_0].i2c_adap,
+   cx231xx_get_i2c_adap(dev, I2C_0),
cx25840, 0x88  1, NULL);
if (dev-sd_cx25840 == NULL)
cx231xx_info(cx25840 subdev registration failure\n);
@@ -1043,8 +1043,10 @@ void cx231xx_card_setup(struct cx231xx *dev)
 
/* Initialize the tuner */
if (dev-board.tuner_type != TUNER_ABSENT) {
+   struct i2c_adapter *tuner_i2c = cx231xx_get_i2c_adap(dev,
+   dev-board.tuner_i2c_master);
dev-sd_tuner = v4l2_i2c_new_subdev(dev-v4l2_dev,
-   
dev-i2c_bus[dev-board.tuner_i2c_master].i2c_adap,
+   tuner_i2c,
tuner,
dev-tuner_addr, NULL);
if (dev-sd_tuner == NULL)
@@ -1062,7 +1064,7 @@ void cx231xx_card_setup(struct cx231xx *dev)
struct i2c_client client;
 
memset(client, 0, sizeof(client));
-   client.adapter = dev-i2c_bus[I2C_1].i2c_adap;
+   client.adapter = cx231xx_get_i2c_adap(dev, I2C_1);
client.addr = 0xa0  1;
 
read_eeprom(dev, client, eeprom, sizeof(eeprom));
diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c 
b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index 6c7b5e2..869c433 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -378,7 +378,7 @@ static int attach_xc5000(u8 addr, struct cx231xx *dev)
struct xc5000_config cfg;
 
memset(cfg, 0, sizeof(cfg));
-   cfg.i2c_adap = dev-i2c_bus[dev-board.tuner_i2c_master].i2c_adap;
+   cfg.i2c_adap = cx231xx_get_i2c_adap(dev, dev-board.tuner_i2c_master);
cfg.i2c_addr = addr;
 
if (!dev-dvb-frontend) {
@@ -583,6 +583,8 @@ static int dvb_init(struct cx231xx *dev)
 {
int result = 0;
struct cx231xx_dvb *dvb;
+   struct i2c_adapter *tuner_i2c;
+   struct i2c_adapter *demod_i2c;
 
if (!dev-board.has_dvb) {
/* This device does not support the extension */
@@ -599,6 +601,8 @@ static int dvb_init(struct cx231xx *dev)
dev-cx231xx_set_analog_freq = cx231xx_set_analog_freq;
dev-cx231xx_reset_analog_tuner = cx231xx_reset_analog_tuner;
 
+   tuner_i2c = cx231xx_get_i2c_adap(dev, dev-board.tuner_i2c_master);
+   demod_i2c = cx231xx_get_i2c_adap(dev, dev-board.demod_i2c_master);
mutex_lock(dev-lock);
cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE);
cx231xx_demod_reset(dev);
@@ -609,7 +613,7 @@ static int dvb_init(struct cx231xx *dev)
 
dev-dvb-frontend = dvb_attach(s5h1432_attach,
dvico_s5h1432_config,
-   
dev-i2c_bus[dev-board.demod_i2c_master].i2c_adap);
+   demod_i2c);
 
if (dev-dvb-frontend == NULL) {
printk(DRIVER_NAME
@@ -622,7 +626,7 @@ static int dvb_init(struct cx231xx *dev)
dvb-frontend-callback = cx231xx_tuner_callback;
 
if (!dvb_attach(xc5000_attach, dev-dvb-frontend,
-  
dev-i2c_bus[dev-board.tuner_i2c_master].i2c_adap,
+  tuner_i2c,
   cnxt_rde250_tunerconfig)) {
result = -EINVAL;
goto out_free;
@@ -634,7 +638,7 @@ static int dvb_init(struct cx231xx *dev)
 
dev-dvb-frontend = dvb_attach(s5h1411_attach

[PATCH v4 04/14] cx231xx: give each master i2c bus a seperate name

2014-10-30 Thread Matthias Schwarzott
V2: Use snprintf to construct the complete name
V3: Remove unneeded variable.

Signed-off-by: Matthias Schwarzott z...@gentoo.org
Reviewed-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/cx231xx/cx231xx-i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c 
b/drivers/media/usb/cx231xx/cx231xx-i2c.c
index a30d400..4505716 100644
--- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
@@ -512,7 +512,7 @@ int cx231xx_i2c_register(struct cx231xx_i2c *bus)
bus-i2c_adap = cx231xx_adap_template;
bus-i2c_adap.dev.parent = dev-udev-dev;
 
-   strlcpy(bus-i2c_adap.name, bus-dev-name, sizeof(bus-i2c_adap.name));
+   snprintf(bus-i2c_adap.name, sizeof(bus-i2c_adap.name), %s-%d, 
bus-dev-name, bus-nr);
 
bus-i2c_adap.algo_data = bus;
i2c_set_adapdata(bus-i2c_adap, dev-v4l2_dev);
-- 
2.1.2

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


[PATCH v4 11/14] cx231xx: register i2c mux adapters for master1 and use as I2C_1_MUX_1 and I2C_1_MUX_3

2014-10-30 Thread Matthias Schwarzott
Signed-off-by: Matthias Schwarzott z...@gentoo.org
Reviewed-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/cx231xx/Kconfig|  1 +
 drivers/media/usb/cx231xx/cx231xx-core.c |  5 
 drivers/media/usb/cx231xx/cx231xx-i2c.c  | 44 +++-
 drivers/media/usb/cx231xx/cx231xx.h  |  4 +++
 4 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/cx231xx/Kconfig 
b/drivers/media/usb/cx231xx/Kconfig
index 569aa29..173c0e2 100644
--- a/drivers/media/usb/cx231xx/Kconfig
+++ b/drivers/media/usb/cx231xx/Kconfig
@@ -7,6 +7,7 @@ config VIDEO_CX231XX
select VIDEOBUF_VMALLOC
select VIDEO_CX25840
select VIDEO_CX2341X
+   select I2C_MUX
 
---help---
  This is a video4linux driver for Conexant 231xx USB based TV cards.
diff --git a/drivers/media/usb/cx231xx/cx231xx-core.c 
b/drivers/media/usb/cx231xx/cx231xx-core.c
index 180103e..c8a6d20 100644
--- a/drivers/media/usb/cx231xx/cx231xx-core.c
+++ b/drivers/media/usb/cx231xx/cx231xx-core.c
@@ -1300,6 +1300,9 @@ int cx231xx_dev_init(struct cx231xx *dev)
cx231xx_i2c_register(dev-i2c_bus[1]);
cx231xx_i2c_register(dev-i2c_bus[2]);
 
+   cx231xx_i2c_mux_register(dev, 0);
+   cx231xx_i2c_mux_register(dev, 1);
+
/* init hardware */
/* Note : with out calling set power mode function,
afe can not be set up correctly */
@@ -1414,6 +1417,8 @@ EXPORT_SYMBOL_GPL(cx231xx_dev_init);
 void cx231xx_dev_uninit(struct cx231xx *dev)
 {
/* Un Initialize I2C bus */
+   cx231xx_i2c_mux_unregister(dev, 1);
+   cx231xx_i2c_mux_unregister(dev, 0);
cx231xx_i2c_unregister(dev-i2c_bus[2]);
cx231xx_i2c_unregister(dev-i2c_bus[1]);
cx231xx_i2c_unregister(dev-i2c_bus[0]);
diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c 
b/drivers/media/usb/cx231xx/cx231xx-i2c.c
index 9ade3ac..3e9dfd8 100644
--- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
@@ -24,6 +24,7 @@
 #include linux/kernel.h
 #include linux/usb.h
 #include linux/i2c.h
+#include linux/i2c-mux.h
 #include media/v4l2-common.h
 #include media/tuner.h
 
@@ -547,6 +548,46 @@ int cx231xx_i2c_unregister(struct cx231xx_i2c *bus)
return 0;
 }
 
+/*
+ * cx231xx_i2c_mux_select()
+ * switch i2c master number 1 between port1 and port3
+ */
+static int cx231xx_i2c_mux_select(struct i2c_adapter *adap,
+   void *mux_priv, u32 chan_id)
+{
+   struct cx231xx *dev = mux_priv;
+
+   return cx231xx_enable_i2c_port_3(dev, chan_id);
+}
+
+int cx231xx_i2c_mux_register(struct cx231xx *dev, int mux_no)
+{
+   struct i2c_adapter *i2c_parent = dev-i2c_bus[1].i2c_adap;
+   /* what is the correct mux_dev? */
+   struct device *mux_dev = dev-udev-dev;
+
+   dev-i2c_mux_adap[mux_no] = i2c_add_mux_adapter(i2c_parent,
+   mux_dev,
+   dev /* mux_priv */,
+   0,
+   mux_no /* chan_id */,
+   0 /* class */,
+   cx231xx_i2c_mux_select,
+   NULL);
+
+   if (!dev-i2c_mux_adap[mux_no])
+   cx231xx_warn(%s: i2c mux %d register FAILED\n,
+dev-name, mux_no);
+
+   return 0;
+}
+
+void cx231xx_i2c_mux_unregister(struct cx231xx *dev, int mux_no)
+{
+   i2c_del_mux_adapter(dev-i2c_mux_adap[mux_no]);
+   dev-i2c_mux_adap[mux_no] = NULL;
+}
+
 struct i2c_adapter *cx231xx_get_i2c_adap(struct cx231xx *dev, int i2c_port)
 {
switch (i2c_port) {
@@ -557,8 +598,9 @@ struct i2c_adapter *cx231xx_get_i2c_adap(struct cx231xx 
*dev, int i2c_port)
case I2C_2:
return dev-i2c_bus[2].i2c_adap;
case I2C_1_MUX_1:
+   return dev-i2c_mux_adap[0];
case I2C_1_MUX_3:
-   return dev-i2c_bus[1].i2c_adap;
+   return dev-i2c_mux_adap[1];
default:
return NULL;
}
diff --git a/drivers/media/usb/cx231xx/cx231xx.h 
b/drivers/media/usb/cx231xx/cx231xx.h
index 8a3c97b..c90aa44 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -628,6 +628,8 @@ struct cx231xx {
 
/* I2C adapters: Master 1  2 (External)  Master 3 (Internal only) */
struct cx231xx_i2c i2c_bus[3];
+   struct i2c_adapter *i2c_mux_adap[2];
+
unsigned int xc_fw_load_done:1;
unsigned int port_3_switch_enabled:1;
/* locks */
@@ -755,6 +757,8 @@ int cx231xx_reset_analog_tuner(struct cx231xx *dev);
 void cx231xx_do_i2c_scan(struct cx231xx *dev, int i2c_port);
 int cx231xx_i2c_register(struct cx231xx_i2c *bus);
 int cx231xx_i2c_unregister(struct cx231xx_i2c *bus);
+int cx231xx_i2c_mux_register(struct cx231xx *dev, int mux_no);
+void cx231xx_i2c_mux_unregister(struct cx231xx *dev, int mux_no);
 struct i2c_adapter *cx231xx_get_i2c_adap

[PATCH v4 14/14] cx231xx: scan all four existing i2c busses instead of the 3 masters

2014-10-30 Thread Matthias Schwarzott
The scanning itself just fails (as before this series) but now the correct 
busses are scanned.

V2: Changed to symbolic names where muxed adapters can be seen directly.
V3: Comment about scanning busses ordered by physical port numbers.

Signed-off-by: Matthias Schwarzott z...@gentoo.org
Reviewed-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/cx231xx/cx231xx-core.c | 6 ++
 drivers/media/usb/cx231xx/cx231xx-i2c.c  | 8 
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-core.c 
b/drivers/media/usb/cx231xx/cx231xx-core.c
index c49022f..9b5cd9e 100644
--- a/drivers/media/usb/cx231xx/cx231xx-core.c
+++ b/drivers/media/usb/cx231xx/cx231xx-core.c
@@ -1303,6 +1303,12 @@ int cx231xx_dev_init(struct cx231xx *dev)
cx231xx_i2c_mux_register(dev, 0);
cx231xx_i2c_mux_register(dev, 1);
 
+   /* scan the real bus segments in the order of physical port numbers */
+   cx231xx_do_i2c_scan(dev, I2C_0);
+   cx231xx_do_i2c_scan(dev, I2C_1_MUX_1);
+   cx231xx_do_i2c_scan(dev, I2C_2);
+   cx231xx_do_i2c_scan(dev, I2C_1_MUX_3);
+
/* init hardware */
/* Note : with out calling set power mode function,
afe can not be set up correctly */
diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c 
b/drivers/media/usb/cx231xx/cx231xx-i2c.c
index 3e9dfd8..d1003c7 100644
--- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
@@ -492,6 +492,9 @@ void cx231xx_do_i2c_scan(struct cx231xx *dev, int i2c_port)
int i, rc;
struct i2c_client client;
 
+   if (!i2c_scan)
+   return;
+
memset(client, 0, sizeof(client));
client.adapter = cx231xx_get_i2c_adap(dev, i2c_port);
 
@@ -528,10 +531,7 @@ int cx231xx_i2c_register(struct cx231xx_i2c *bus)
i2c_set_adapdata(bus-i2c_adap, dev-v4l2_dev);
i2c_add_adapter(bus-i2c_adap);
 
-   if (0 == bus-i2c_rc) {
-   if (i2c_scan)
-   cx231xx_do_i2c_scan(dev, bus-nr);
-   } else
+   if (0 != bus-i2c_rc)
cx231xx_warn(%s: i2c bus %d register FAILED\n,
 dev-name, bus-nr);
 
-- 
2.1.2

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


[PATCH v4 08/14] cx231xx: remember status of i2c port_3 switch

2014-10-30 Thread Matthias Schwarzott
This is used later for is_tuner function that switches i2c behaviour for
some tuners.

V2: Add comments about possible improvements for port_3 switch function.
V3: Fix coding style.

Signed-off-by: Matthias Schwarzott z...@gentoo.org
---
 drivers/media/usb/cx231xx/cx231xx-avcore.c | 12 
 drivers/media/usb/cx231xx/cx231xx.h|  1 +
 2 files changed, 13 insertions(+)

diff --git a/drivers/media/usb/cx231xx/cx231xx-avcore.c 
b/drivers/media/usb/cx231xx/cx231xx-avcore.c
index 40a6987..0a5fec4 100644
--- a/drivers/media/usb/cx231xx/cx231xx-avcore.c
+++ b/drivers/media/usb/cx231xx/cx231xx-avcore.c
@@ -1272,6 +1272,14 @@ int cx231xx_enable_i2c_port_3(struct cx231xx *dev, bool 
is_port_3)
 
if (dev-board.dont_use_port_3)
is_port_3 = false;
+
+   /*
+* Should this code check dev-port_3_switch_enabled first
+* to skip unnecessary reading of the register?
+* If yes, the flag dev-port_3_switch_enabled must be initialized
+* correctly.
+*/
+
status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER,
   PWR_CTL_EN, value, 4);
if (status  0)
@@ -1294,6 +1302,10 @@ int cx231xx_enable_i2c_port_3(struct cx231xx *dev, bool 
is_port_3)
status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
PWR_CTL_EN, value, 4);
 
+   /* remember status of the switch for usage in is_tuner */
+   if (status = 0)
+   dev-port_3_switch_enabled = is_port_3;
+
return status;
 
 }
diff --git a/drivers/media/usb/cx231xx/cx231xx.h 
b/drivers/media/usb/cx231xx/cx231xx.h
index f03338b..8a3c97b 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -629,6 +629,7 @@ struct cx231xx {
/* I2C adapters: Master 1  2 (External)  Master 3 (Internal only) */
struct cx231xx_i2c i2c_bus[3];
unsigned int xc_fw_load_done:1;
+   unsigned int port_3_switch_enabled:1;
/* locks */
struct mutex gpio_i2c_lock;
struct mutex i2c_lock;
-- 
2.1.2

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


[PATCH v4 09/14] cx231xx: let is_tuner check the real i2c port and not the i2c master number

2014-10-30 Thread Matthias Schwarzott
Get used i2c port from bus_nr and status of port_3 switch.

Signed-off-by: Matthias Schwarzott z...@gentoo.org
---
 drivers/media/usb/cx231xx/cx231xx-i2c.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c 
b/drivers/media/usb/cx231xx/cx231xx-i2c.c
index af9180f..9ade3ac 100644
--- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
@@ -54,10 +54,19 @@ do {
\
   }\
 } while (0)
 
+static inline int get_real_i2c_port(struct cx231xx *dev, int bus_nr)
+{
+   if (bus_nr == 1)
+   return dev-port_3_switch_enabled ? I2C_1_MUX_3 : I2C_1_MUX_1;
+   return bus_nr;
+}
+
 static inline bool is_tuner(struct cx231xx *dev, struct cx231xx_i2c *bus,
const struct i2c_msg *msg, int tuner_type)
 {
-   if (bus-nr != dev-board.tuner_i2c_master)
+   int i2c_port = get_real_i2c_port(dev, bus-nr);
+
+   if (i2c_port != dev-board.tuner_i2c_master)
return false;
 
if (msg-addr != dev-board.tuner_addr)
-- 
2.1.2

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


[PATCH v4 01/14] cx231xx: let i2c bus scanning use its own i2c_client

2014-10-30 Thread Matthias Schwarzott
This is a preparation for deleting the otherwise useless i2c_clients
that are allocated for all the i2c master adapters.

Signed-off-by: Matthias Schwarzott z...@gentoo.org
Reviewed-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/cx231xx/cx231xx-i2c.c | 17 +++--
 drivers/media/usb/cx231xx/cx231xx.h |  2 +-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c 
b/drivers/media/usb/cx231xx/cx231xx-i2c.c
index 7c0f797..67a1391 100644
--- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
@@ -480,22 +480,27 @@ static char *i2c_devs[128] = {
  * cx231xx_do_i2c_scan()
  * check i2c address range for devices
  */
-void cx231xx_do_i2c_scan(struct cx231xx *dev, struct i2c_client *c)
+void cx231xx_do_i2c_scan(struct cx231xx *dev, int i2c_port)
 {
unsigned char buf;
int i, rc;
+   struct i2c_client client;
 
-   cx231xx_info(: Checking for I2C devices ..\n);
+   memset(client, 0, sizeof(client));
+   client.adapter = dev-i2c_bus[i2c_port].i2c_adap;
+
+   cx231xx_info(: Checking for I2C devices on port=%d ..\n, i2c_port);
for (i = 0; i  128; i++) {
-   c-addr = i;
-   rc = i2c_master_recv(c, buf, 0);
+   client.addr = i;
+   rc = i2c_master_recv(client, buf, 0);
if (rc  0)
continue;
cx231xx_info(%s: i2c scan: found device @ 0x%x  [%s]\n,
 dev-name, i  1,
 i2c_devs[i] ? i2c_devs[i] : ???);
}
-   cx231xx_info(: Completed Checking for I2C devices.\n);
+   cx231xx_info(: Completed Checking for I2C devices on port=%d.\n,
+   i2c_port);
 }
 
 /*
@@ -522,7 +527,7 @@ int cx231xx_i2c_register(struct cx231xx_i2c *bus)
 
if (0 == bus-i2c_rc) {
if (i2c_scan)
-   cx231xx_do_i2c_scan(dev, bus-i2c_client);
+   cx231xx_do_i2c_scan(dev, bus-nr);
} else
cx231xx_warn(%s: i2c bus %d register FAILED\n,
 dev-name, bus-nr);
diff --git a/drivers/media/usb/cx231xx/cx231xx.h 
b/drivers/media/usb/cx231xx/cx231xx.h
index aeb1bf4..5efc93e 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -751,7 +751,7 @@ int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq);
 int cx231xx_reset_analog_tuner(struct cx231xx *dev);
 
 /* Provided by cx231xx-i2c.c */
-void cx231xx_do_i2c_scan(struct cx231xx *dev, struct i2c_client *c);
+void cx231xx_do_i2c_scan(struct cx231xx *dev, int i2c_port);
 int cx231xx_i2c_register(struct cx231xx_i2c *bus);
 int cx231xx_i2c_unregister(struct cx231xx_i2c *bus);
 
-- 
2.1.2

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


[PATCH v4 05/14] cx231xx: Modifiy the symbolic constants for i2c ports and describe

2014-10-30 Thread Matthias Schwarzott
Change to I2C_0 ... I2C_2 for the master ports
and add I2C_1_MUX_1 and I2C_1_MUX_3 for the muxed ones.

V2: Renamed mux adapters to seperate them from master adapters.

Signed-off-by: Matthias Schwarzott z...@gentoo.org
Reviewed-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/cx231xx/cx231xx.h | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx.h 
b/drivers/media/usb/cx231xx/cx231xx.h
index c92382f..377216b 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -322,10 +322,11 @@ enum cx231xx_decoder {
 };
 
 enum CX231XX_I2C_MASTER_PORT {
-   I2C_0 = 0,
-   I2C_1 = 1,
-   I2C_2 = 2,
-   I2C_3 = 3
+   I2C_0 = 0,   /* master 0 - internal connection */
+   I2C_1 = 1,   /* master 1 - used with mux */
+   I2C_2 = 2,   /* master 2 */
+   I2C_1_MUX_1 = 3, /* master 1 - port 1 (I2C_DEMOD_EN = 0) */
+   I2C_1_MUX_3 = 4  /* master 1 - port 3 (I2C_DEMOD_EN = 1) */
 };
 
 struct cx231xx_board {
-- 
2.1.2

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


[PATCH v4 06/14] cx231xx: Use symbolic constants for i2c ports instead of numbers

2014-10-30 Thread Matthias Schwarzott
Replace numbers by the constants of same value and same meaning.

Signed-off-by: Matthias Schwarzott z...@gentoo.org
Reviewed-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/cx231xx/cx231xx-cards.c | 62 +++
 1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c 
b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 092fb85..2f027c7 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -104,8 +104,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = 1,
-   .demod_i2c_master = 2,
+   .tuner_i2c_master = I2C_1,
+   .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
.norm = V4L2_STD_PAL,
@@ -144,8 +144,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = 1,
-   .demod_i2c_master = 2,
+   .tuner_i2c_master = I2C_1,
+   .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x32,
.norm = V4L2_STD_NTSC,
@@ -184,8 +184,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFC4,
.agc_analog_digital_select_gpio = 0x1c,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = 1,
-   .demod_i2c_master = 2,
+   .tuner_i2c_master = I2C_1,
+   .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
.norm = V4L2_STD_PAL,
@@ -225,8 +225,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFC4,
.agc_analog_digital_select_gpio = 0x1c,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = 1,
-   .demod_i2c_master = 2,
+   .tuner_i2c_master = I2C_1,
+   .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
.norm = V4L2_STD_PAL,
@@ -297,8 +297,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = 1,
-   .demod_i2c_master = 2,
+   .tuner_i2c_master = I2C_1,
+   .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
.norm = V4L2_STD_PAL,
@@ -325,8 +325,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = 1,
-   .demod_i2c_master = 2,
+   .tuner_i2c_master = I2C_1,
+   .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x32,
.norm = V4L2_STD_NTSC,
@@ -353,8 +353,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = 1,
-   .demod_i2c_master = 2,
+   .tuner_i2c_master = I2C_1,
+   .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x0e,
.norm = V4L2_STD_NTSC,
@@ -418,9 +418,9 @@ struct cx231xx_board cx231xx_boards[] = {
.tuner_scl_gpio = -1,
.tuner_sda_gpio = -1,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = 2,
-   .demod_i2c_master = 1,
-   .ir_i2c_master = 2,
+   .tuner_i2c_master = I2C_2,
+   .demod_i2c_master = I2C_1,
+   .ir_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x10,
.norm = V4L2_STD_PAL_M,
@@ -456,9 +456,9 @@ struct cx231xx_board cx231xx_boards[] = {
.tuner_scl_gpio = -1,
.tuner_sda_gpio = -1,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = 2,
-   .demod_i2c_master = 1,
-   .ir_i2c_master = 2,
+   .tuner_i2c_master = I2C_2,
+   .demod_i2c_master = I2C_1,
+   .ir_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x10,
.norm

[PATCH v4 10/14] cx231xx: change usage of I2C_1 to the real i2c port

2014-10-30 Thread Matthias Schwarzott
change almost all instances of I2C_1 to I2C_1_MUX_3

Only these cases are changed to I2C_1_MUX_1:
* All that have dont_use_port_3 set.
* CX231XX_BOARD_HAUPPAUGE_EXETER, old code did explicitly not switch to port3.
* eeprom access for 930C

Signed-off-by: Matthias Schwarzott z...@gentoo.org
Reviewed-by: Antti Palosaari cr...@iki.fi
---
 drivers/media/usb/cx231xx/cx231xx-cards.c | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c 
b/drivers/media/usb/cx231xx/cx231xx-cards.c
index f5fb93a..4eb2057 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -104,7 +104,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = I2C_1,
+   .tuner_i2c_master = I2C_1_MUX_3,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
@@ -144,7 +144,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = I2C_1,
+   .tuner_i2c_master = I2C_1_MUX_3,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x32,
@@ -184,7 +184,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFC4,
.agc_analog_digital_select_gpio = 0x1c,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = I2C_1,
+   .tuner_i2c_master = I2C_1_MUX_3,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
@@ -225,7 +225,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFC4,
.agc_analog_digital_select_gpio = 0x1c,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = I2C_1,
+   .tuner_i2c_master = I2C_1_MUX_3,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
@@ -297,7 +297,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = I2C_1,
+   .tuner_i2c_master = I2C_1_MUX_3,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
@@ -325,7 +325,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = I2C_1,
+   .tuner_i2c_master = I2C_1_MUX_3,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x32,
@@ -353,7 +353,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
-   .tuner_i2c_master = I2C_1,
+   .tuner_i2c_master = I2C_1_MUX_1,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x0e,
@@ -419,7 +419,7 @@ struct cx231xx_board cx231xx_boards[] = {
.tuner_sda_gpio = -1,
.gpio_pin_status_mask = 0x4001000,
.tuner_i2c_master = I2C_2,
-   .demod_i2c_master = I2C_1,
+   .demod_i2c_master = I2C_1_MUX_3,
.ir_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x10,
@@ -457,7 +457,7 @@ struct cx231xx_board cx231xx_boards[] = {
.tuner_sda_gpio = -1,
.gpio_pin_status_mask = 0x4001000,
.tuner_i2c_master = I2C_2,
-   .demod_i2c_master = I2C_1,
+   .demod_i2c_master = I2C_1_MUX_3,
.ir_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x10,
@@ -495,7 +495,7 @@ struct cx231xx_board cx231xx_boards[] = {
.tuner_sda_gpio = -1,
.gpio_pin_status_mask = 0x4001000,
.tuner_i2c_master = I2C_2,
-   .demod_i2c_master = I2C_1,
+   .demod_i2c_master = I2C_1_MUX_3,
.ir_i2c_master = I2C_2,
.rc_map_name = RC_MAP_PIXELVIEW_002T,
.has_dvb = 1,
@@ -587,7 +587,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFC4,
.agc_analog_digital_select_gpio

[PATCH] cx231xx: remove direct register PWR_CTL_EN modification that switches port3

2014-10-30 Thread Matthias Schwarzott
The only remaining place that modifies the relevant bit is in function
cx231xx_set_Colibri_For_LowIF

Signed-off-by: Matthias Schwarzott z...@gentoo.org
---
 drivers/media/usb/cx231xx/cx231xx-avcore.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-avcore.c 
b/drivers/media/usb/cx231xx/cx231xx-avcore.c
index b56bc87..781908b 100644
--- a/drivers/media/usb/cx231xx/cx231xx-avcore.c
+++ b/drivers/media/usb/cx231xx/cx231xx-avcore.c
@@ -2270,7 +2270,6 @@ int cx231xx_set_power_mode(struct cx231xx *dev, enum 
AV_MODE mode)
case POLARIS_AVMODE_ANALOGT_TV:
 
tmp |= PWR_DEMOD_EN;
-   tmp |= (I2C_DEMOD_EN);
value[0] = (u8) tmp;
value[1] = (u8) (tmp  8);
value[2] = (u8) (tmp  16);
@@ -2366,7 +2365,7 @@ int cx231xx_set_power_mode(struct cx231xx *dev, enum 
AV_MODE mode)
}
 
tmp = (~PWR_AV_MODE);
-   tmp |= POLARIS_AVMODE_DIGITAL | I2C_DEMOD_EN;
+   tmp |= POLARIS_AVMODE_DIGITAL;
value[0] = (u8) tmp;
value[1] = (u8) (tmp  8);
value[2] = (u8) (tmp  16);
-- 
2.1.2

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


  1   2   3   >