as102: fix regression in kernel 3.3
Subsystems (2)
cover as102: fix regression in kernel 3.3
When I first tried the as102 driver in the 3.3 kernel, I was pleased to notice that finally my stick was able to tune VHF channels. It never worked in VHF even with the original Kernellabs driver.
But a few days ago a linux user from Melbourne, Ryley, contacted me to let me know he had a completely different experience: his Elgato stick was able to tune VHF channels with the 3.2 driver, but not with the 3.3 one.
Ryley tracked down the issue to this patch:
http://patchwork.linuxtv.org/patch/8332/
In that patch, "#pragma pack(1)" is replaced with "__packed" attributes, but it is not complete.
Patch 1 fixes the regression.
It also fixes the issue reported by Ryley, and his Elgato sticks works again with VHF channels. But this patch also breaks again VHF tuning with my reference design stick.
So I investigated the real effect of the regression: it turned out that the only struct really affected was "as10x_fw_context".
The as10x_fw_context command is only used in two functions:as10x_cmd_set_context() and as10x_cmd_get_context().
as10x_cmd_get_context() is not used anywhere in the driver.
as10x_cmd_set_context() is only used in one place in the driver:
in function as102_fe_ts_bus_ctrl (file as102_fe.c, line 252):
if (acquire) {
if (elna_enable)
as10x_cmd_set_context(&dev->bus_adap, 1010, 0xC0);.....
So the command is only used to enable the eLNA (Low Noise Amplifier). In kernel 3.3, the command failed silently due to bad formatting, so the eLNA amplifier was never enabled.
But disabling the eLNA amplifier is not optimal even for my stick, so I played with the eLNA configuration value (hardcoded to 0xC0 in the original code). I found that for my stick the optimal value is 0xA0.
Patch 2 introduces device specific eLNA configuration values. With this patch, all as102 sticks should work out-of-the-box with both UHF and VHF channels.
Gianluca Gennari (2):
as102: add __packed attribute to structs defined inside packed structs
as102: set optimal eLNA config values for each device
drivers/staging/media/as102/as102_drv.h | 2 +- drivers/staging/media/as102/as102_fe.c | 2 +- drivers/staging/media/as102/as102_fw.h | 2 +- drivers/staging/media/as102/as102_usb_drv.c | 15 +++++- drivers/staging/media/as102/as10x_cmd.h | 80 +++++++++++++------------- drivers/staging/media/as102/as10x_types.h | 2 +- 6 files changed, 58 insertions(+), 45 deletions(-)
PATCH 1/2 as102: add __packed attribute to structs defined inside packed structs
This patch fixes a regression in kernel 3.3 due to this patch:
http://patchwork.linuxtv.org/patch/8332/
That patch changes "#pragma pack(1)" with "__packed" attributes, but it is not complete. In fact, in the as102 driver there are a lot of structs/unions defined inside other structs/unions.
When the "__packed" attribute is applied only on the external struct, it will not affect the internal struct definitions.
So the regression is fixed by specifiying the "__packed" attribute also on the internal structs.
This patch should go into 3.3, as it fixes a regression introduced in the new kernel version.
--- drivers/staging/media/as102/as102_fw.h | 2 +- drivers/staging/media/as102/as10x_cmd.h | 80 ++++++++++++++-------------- drivers/staging/media/as102/as10x_types.h | 2 +- 3 files changed, 42 insertions(+), 42 deletions(-)
drivers/staging/media/as102/as102_fw.h +1 -1
@@ -29,7 +29,7 @@ struct as10x_fw_pkt_t {union {unsigned char request[2 ];unsigned char length[2 ]; - } u; + } __packed u;struct as10x_raw_fw_pkt raw; } __packed;
drivers/staging/media/as102/as10x_cmd.h +40 -40
314 lines not on this page · raw message
drivers/staging/media/as102/as10x_types.h +1 -1
@@ -181,7 +181,7 @@ struct as10x_register_value {uint8_t value8;/* 8 bit value */ uint16_t value16;/* 16 bit value */ uint32_t value32;/* 32 bit value */ - } u; + }__packed u; } __packed;struct as10x_register_addr {
Signature · 1 line
1.7.0.4
PATCH 2/2 as102: set optimal eLNA config values for each device
In reply to Gianluca GennariRyley and me tested several eLNA configuration values with both a rooftop and a portable antenna.
Ryley fuond out that the best value for his Elgato stick is indeed the current default value 0xC0.
Instead, my stick is not capable of tuning VHF channels with 0xC0. With 0x80, VHF works but the tuner sensitivity with the portable antenna is poor. Instead, the value 0xA0 works with VHF and also gives good performance with both the rooftop and the portable antenna.
So we concluded that devices built on the reference design work best with 0xA0, while custom designs (Elgato, PCTV) seem to require 0xC0.
I also removed the unused parameter "minor" in struct as102_dev_t.
--- drivers/staging/media/as102/as102_drv.h | 2 +- drivers/staging/media/as102/as102_fe.c | 2 +- drivers/staging/media/as102/as102_usb_drv.c | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-)
drivers/staging/media/as102/as102_drv.h +1 -1
@@ -76,7 +76,7 @@ struct as102_dev_t {struct as10x_bus_adapter_t bus_adap;struct list_head device_entry;struct kref kref; -unsigned long minor; +uint8_t elna_cfg;struct dvb_adapter dvb_adap;struct dvb_frontend dvb_fe;
drivers/staging/media/as102/as102_fe.c +1 -1
@@ -265,7 +265,7 @@ static int as102_fe_ts_bus_ctrl(struct dvb_frontend *fe, int acquire)if (acquire) {if (elna_enable) -as10x_cmd_set_context (&dev->bus_adap,1010 ,0xC0 ); +as10x_cmd_set_context (&dev->bus_adap,CONTEXT_LNA , dev->elna_cfg); ret =as10x_cmd_turn_on (&dev->bus_adap); }else {
drivers/staging/media/as102/as102_usb_drv.c +14 -1
@@ -57,6 +57,17 @@ static const char * const as102_device_names[] = {NULL /* Terminating entry */ }; +/* eLNA configuration: devices built on the reference design work best +with 0xA0, while custom designs seem to require 0xC0 */ +static uint8_t const as102_elna_cfg[] = { +0xA0 , +0xC0 , +0xC0 , +0xA0 , +0xA0 , +0x00 /* Terminating entry */ +}; +struct usb_driver as102_usb_driver = { .name =DRIVER_FULL_NAME , .probe = as102_usb_probe,
@@ -369,8 +380,10 @@ static int as102_usb_probe(struct usb_interface *intf,/* Assign the user-friendly device name */ for (i =0 ; i < (sizeof (as102_usb_id_table) /sizeof (struct usb_device_id )); i++) { -if (id == &as102_usb_id_table[i]) +if (id == &as102_usb_id_table[i]) { as102_dev->name = as102_device_names[i]; + as102_dev->elna_cfg = as102_elna_cfg[i]; + } }if (as102_dev->name ==NULL )
Signature · 1 line
1.7.0.4