mb86a20s: improve error handling at get_frontend
Subsystems (2)
RFC PATCH v11 1/16 mb86a20s: improve error handling at get_frontend
The read/write errors are not handled well on get_frontend. Fix it, by letting the frontend cached values to represent the DVB properties that were successfully retrieved.
While here, use "c" for dtv_frontend_properties cache, instead of "p", as this is more common.
--- drivers/media/dvb-frontends/mb86a20s.c | 138 +++++++++++++++++++-------------- 1 file changed, 80 insertions(+), 58 deletions(-)
drivers/media/dvb-frontends/mb86a20s.c +80 -58
@@ -1,11 +1,9 @@/* * Fujitu mb86a20s ISDB-T/ISDB-Tsb Module driver * -* Copyright (C) 2010 Mauro Carvalho Chehab <[email protected]> +* Copyright (C) 2010-2013 Mauro Carvalho Chehab <[email protected]> * Copyright (C) 2009-2010 Douglas Landgraf <[email protected]> * -* FIXME: Need to port to DVB v5.2 API -* * 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 version 2.
@@ -360,7 +358,7 @@ static int mb86a20s_set_frontend(struct dvb_frontend *fe)/* * FIXME: Properly implement the set frontend properties */ -struct dtv_frontend_properties *p = &fe->dtv_property_cache; +struct dtv_frontend_properties *c = &fe->dtv_property_cache;#endif dprintk ("\n" );
@@ -507,93 +505,117 @@ static int mb86a20s_get_segment_count(struct mb86a20s_state *state,return count; } +static void mb86a20s_reset_frontend_cache (struct dvb_frontend *fe) +{ +struct dtv_frontend_properties *c = &fe->dtv_property_cache; + +/* Fixed parameters */ + c->delivery_system =SYS_ISDBT ; + c->bandwidth_hz =6000000 ; + +/* Initialize values that will be later autodetected */ + c->isdbt_layer_enabled =0 ; + c->transmission_mode =TRANSMISSION_MODE_AUTO ; + c->guard_interval =GUARD_INTERVAL_AUTO ; + c->isdbt_sb_mode =0 ; + c->isdbt_sb_segment_count =0 ; +} +static int mb86a20s_get_frontend (struct dvb_frontend *fe) {struct mb86a20s_state *state = fe->demodulator_priv; -struct dtv_frontend_properties *p = &fe->dtv_property_cache; +struct dtv_frontend_properties *c = &fe->dtv_property_cache;int i, rc; -/* Fixed parameters */ - p->delivery_system =SYS_ISDBT ; - p->bandwidth_hz =6000000 ; +/* Reset frontend cache to default values */ +mb86a20s_reset_frontend_cache (fe);if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl (fe,0 );/* Check for partial reception */ rc =mb86a20s_writereg (state,0x6d ,0x85 ); -if (rc >=0 ) - rc =mb86a20s_readreg (state,0x6e ); -if (rc >=0 ) - p->isdbt_partial_reception = (rc &0x10 ) ?1 :0 ; +if (rc <0 ) +return rc; + rc =mb86a20s_readreg (state,0x6e ); +if (rc <0 ) +return rc; + c->isdbt_partial_reception = (rc &0x10 ) ?1 :0 ;/* Get per-layer data */ - p->isdbt_layer_enabled =0 ; +for (i =0 ; i <3 ; i++) { rc =mb86a20s_get_segment_count (state, i); -if (rc >=0 && rc <14 ) - p->layer[i].segment_count = rc; -if (rc ==0x0f ) +if (rc <0 ) + goto error; +if (rc >=0 && rc <14 ) + c->layer[i].segment_count = rc; +else { + c->layer[i].segment_count =0 ;continue ; - p->isdbt_layer_enabled |=1 << i; + } + c->isdbt_layer_enabled |=1 << i; rc =mb86a20s_get_modulation (state, i); -if (rc >=0 ) - p->layer[i].modulation = rc; +if (rc <0 ) + goto error; + c->layer[i].modulation = rc; rc =mb86a20s_get_fec (state, i); -if (rc >=0 ) - p->layer[i].fec = rc; +if (rc <0 ) + goto error; + c->layer[i].fec = rc; rc =mb86a20s_get_interleaving (state, i); -if (rc >=0 ) - p->layer[i].interleaving = rc; +if (rc <0 ) + goto error; + c->layer[i].interleaving = rc; } - p->isdbt_sb_mode =0 ; rc =mb86a20s_writereg (state,0x6d ,0x84 ); -if ((rc >=0 ) && ((rc &0x60 ) ==0x20 )) { - p->isdbt_sb_mode =1 ; +if (rc <0 ) +return rc; +if ((rc &0x60 ) ==0x20 ) { + c->isdbt_sb_mode =1 ;/* At least, one segment should exist */ -if (!p->isdbt_sb_segment_count) - p->isdbt_sb_segment_count =1 ; - }else - p->isdbt_sb_segment_count =0 ; +if (!c->isdbt_sb_segment_count) + c->isdbt_sb_segment_count =1 ; + }/* Get transmission mode and guard interval */ - p->transmission_mode =TRANSMISSION_MODE_AUTO ; - p->guard_interval =GUARD_INTERVAL_AUTO ; rc =mb86a20s_readreg (state,0x07 ); -if (rc >=0 ) { -if ((rc &0x60 ) ==0x20 ) { -switch (rc &0x0c >>2 ) { -case 0 : - p->transmission_mode =TRANSMISSION_MODE_2K ; -break ; -case 1 : - p->transmission_mode =TRANSMISSION_MODE_4K ; -break ; -case 2 : - p->transmission_mode =TRANSMISSION_MODE_8K ; -break ; - } +if (rc <0 ) +return rc; +if ((rc &0x60 ) ==0x20 ) { +switch (rc &0x0c >>2 ) { +case 0 : + c->transmission_mode =TRANSMISSION_MODE_2K ; +break ; +case 1 : + c->transmission_mode =TRANSMISSION_MODE_4K ; +break ; +case 2 : + c->transmission_mode =TRANSMISSION_MODE_8K ; +break ; } -if (!(rc &0x10 )) { -switch (rc &0x3 ) { -case 0 : - p->guard_interval =GUARD_INTERVAL_1_4 ; -break ; -case 1 : - p->guard_interval =GUARD_INTERVAL_1_8 ; -break ; -case 2 : - p->guard_interval =GUARD_INTERVAL_1_16 ; -break ; - } + } +if (!(rc &0x10 )) { +switch (rc &0x3 ) { +case 0 : + c->guard_interval =GUARD_INTERVAL_1_4 ; +break ; +case 1 : + c->guard_interval =GUARD_INTERVAL_1_8 ; +break ; +case 2 : + c->guard_interval =GUARD_INTERVAL_1_16 ; +break ; } } +error:if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl (fe,1 ); -return 0 ; +return rc; + } static int mb86a20s_tune(struct dvb_frontend *fe,
Signature · 1 line
1.7.11.7
RFC PATCH v11 2/16 dvb: Add DVBv5 statistics properties
The DVBv3 statistics parameters are limited on several ways:
- Doesn't provide any way to indicate the used measure, so userspace need to guess how to calculate the measure;
- Only a limited set of stats are supported;
- Can't be called in a way to require them to be filled all at once (atomic reads from the hardware), with may cause troubles on interpreting them on userspace;
- On some OFDM delivery systems, the carriers can be independently modulated, having different properties. Currently, there's no way to report per-layer stats.
To address the above issues, adding a new DVBv5-based stats API.
--- Documentation/DocBook/media/dvb/dvbproperty.xml | 99 +++++++++++++++++++++++++ include/uapi/linux/dvb/frontend.h | 77 ++++++++++++++++++- 2 files changed, 175 insertions(+), 1 deletion(-)
v11:
- Renamed from QoS to Statistics
- Removed ENUM Stats property. This is not needed, as unsupported measures will return u.len = 0;
- Statistics cache reset is now a driver's decision.
Documentation/DocBook/media/dvb/dvbproperty.xml +99 -0
@@ -7,14 +7,41 @@ the capability ioctls weren't implemented yet via the new way.</para> <para>The typical usage for the <constant>FE_GET_PROPERTY/FE_SET_PROPERTY</constant> API is to replace the ioctl's were the <link linkend="dvb-frontend-parameters"> struct <constant>dvb_frontend_parameters</constant></link> were used.</para> +<section id="dtv-stats"> +<title>DTV stats type</title> +<programlisting> +struct dtv_stats { + __u8 scale; /* enum fecap_scale_params type */ + union { + __u64 uvalue; /* for counters and relative scales */ + __s64 svalue; /* for 1/1000 dB measures */ + }; +} __packed; +</programlisting> +</section> +<section id="dtv-fe-stats"> +<title>DTV stats type</title> +<programlisting> +#define MAX_DTV_STATS 4 + +struct dtv_fe_stats { + __u8 len; + struct dtv_stats stat[MAX_DTV_STATS]; +} __packed; +</programlisting> +</section> + <section id="dtv-property"> <title>DTV property type</title> <programlisting> /* Reserved fields should be set to 0 */ + struct dtv_property { __u32 cmd; + __u32 reserved[3]; union { __u32 data; + struct dtv_fe_stats st; struct { __u8 data[32]; __u32 len;
@@ -850,6 +877,68 @@ enum fe_interleaving { <para>use the special macro LNA_AUTO to set LNA auto</para> </section> </section> + + <section id="frontend-stat-properties"> + <title>Frontend statistics indicators</title> + <para>The values are returned via <constant>dtv_property.stat</constant>.</para> + <para>For most delivery systems, this will return a single value for each parameter.</para> + <para>It should be noticed, however, that new OFDM delivery systems + like ISDB can use different modulation types for each group of carriers. + On such standards, up to 3 groups of statistics can be provided, one + for each carrier group (called "layer" on ISDB). + In order to be consistent with other delivery systems, the first + value at <link linkend="dtv-stats"><constant>dtv_property.stat.dtv_stats</constant></link> array refers to + a global indicator, if any. The other elements of the array represent + each layer, starting from layer A(index 1), layer B (index 2) and so on</para> + <para>The number of filled elements are stored at <constant>dtv_property.stat.len</constant>.</para> + <para>Each element of the <constant>dtv_property.stat.dtv_stats</constant> array consists on two elements:</para> + <itemizedlist mark='opencircle'> + <listitem><para><constant>value</constant> - Value of the measure</para></listitem> + <listitem><para><constant>scale</constant> - Scale for the value. It can be:</para> + <section id = "fecap-scale-params"> + <itemizedlist mark='bullet'> + <listitem><para><constant>FE_SCALE_NOT_AVAILABLE</constant> - If it is not possible to collect a given parameter (could be a transitory or permanent condition)</para></listitem> + <listitem><para><constant>FE_SCALE_DECIBEL</constant> - parameter is a signed value, measured in 1/1000 dB</para></listitem> + <listitem><para><constant>FE_SCALE_RELATIVE</constant> - parameter is a unsigned value, where 0 means 0% and 65535 means 100%.</para></listitem> + <listitem><para><constant>FE_SCALE_COUNTER</constant> - parameter is a unsigned value that counts the occurrence of an event, like bit error, block error, or lapsed time.</para></listitem> + </itemizedlist> + </section> + </listitem> + </itemizedlist> + <section id="DTV-STAT-SIGNAL-STRENGTH"> + <title><constant>DTV_STAT_SIGNAL_STRENGTH</constant></title> + <para>Indicates the signal strength level at the analog part of the tuner.</para> + <para>When measured in 1/1000 dB scale(<link linkend="fecap-scale-params"><constant>FE_SCALE_DECIBEL</constant></link>), is measured in mili Watts, e. g., a value of 1 means 0.0001 dBm.</para> + </section> + <section id="DTV-STAT-CNR"> + <title><constant>DTV_STAT_CNR</constant></title> + <para>Indicates the signal to noise relation for the main carrier.</para> + + </section> + <section id="DTV-STAT-BIT-ERROR-COUNT"> + <title><constant>DTV_STAT_BIT_ERROR_COUNT</constant></title> + <para>Measures the number of bit errors since the last counter reset.</para> + <para>In order to get the BER (Bit Error Rate) measurement, it should be divided by + <link linkend="DTV-STAT-TOTAL-BITS-COUNT"><constant>DTV_STAT_TOTAL_BITS_COUNT</constant></link>.</para> + </section> + <section id="DTV-STAT-TOTAL-BITS-COUNT"> + <title><constant>DTV_STAT_TOTAL_BITS_COUNT</constant></title> + <para>Measures the amount of bits received since the last <link linkend="DTV-STAT-BIT-ERROR-COUNT"><constant>DTV_STAT_BIT_ERROR_COUNT</constant></link> reset.</para> + </section> + <section id="DTV-STAT-ERROR-BLOCK-COUNT"> + <title><constant>DTV_STAT_ERROR_BLOCK_COUNT</constant></title> + <para>Measures the number of block errors since the last counter reset.</para> + </section> + <section id="DTV-STAT-TOTAL-BLOCKS-COUNT"> + <title><constant>DTV-STAT_TOTAL_BLOCKS_COUNT</constant></title> + <para>Measures the total number of blocks since the last + <link linkend="DTV-STAT-ERROR-BLOCK-COUNT"><constant>DTV_STAT_ERROR_BLOCK_COUNT</constant></link> reset.</para> + <para>It can be used to calculate the PER indicator, by dividing + <link linkend="DTV-STAT-ERROR-BLOCK-COUNT"><constant>DTV_STAT_ERROR_BLOCK_COUNT</constant></link> + by <link linkend="DTV-STAT-TOTAL-BLOCKS-COUNT"><constant>DTV-STAT-TOTAL-BLOCKS-COUNT</constant></link>.</para> + </section> + </section> + <section id="frontend-property-terrestrial-systems"> <title>Properties used on terrestrial delivery systems</title> <section id="dvbt-params">
@@ -871,6 +960,7 @@ enum fe_interleaving { <listitem><para><link linkend="DTV-HIERARCHY"><constant>DTV_HIERARCHY</constant></link></para></listitem> <listitem><para><link linkend="DTV-LNA"><constant>DTV_LNA</constant></link></para></listitem> </itemizedlist> + <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para> </section> <section id="dvbt2-params"> <title>DVB-T2 delivery system</title>
@@ -895,6 +985,7 @@ enum fe_interleaving { <listitem><para><link linkend="DTV-STREAM-ID"><constant>DTV_STREAM_ID</constant></link></para></listitem> <listitem><para><link linkend="DTV-LNA"><constant>DTV_LNA</constant></link></para></listitem> </itemizedlist> + <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para> </section> <section id="isdbt"> <title>ISDB-T delivery system</title>
@@ -948,6 +1039,7 @@ enum fe_interleaving { <listitem><para><link linkend="DTV-ISDBT-LAYER-SEGMENT-COUNT"><constant>DTV_ISDBT_LAYERC_SEGMENT_COUNT</constant></link></para></listitem> <listitem><para><link linkend="DTV-ISDBT-LAYER-TIME-INTERLEAVING"><constant>DTV_ISDBT_LAYERC_TIME_INTERLEAVING</constant></link></para></listitem> </itemizedlist> + <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para> </section> <section id="atsc-params"> <title>ATSC delivery system</title>
@@ -961,6 +1053,7 @@ enum fe_interleaving { <listitem><para><link linkend="DTV-MODULATION"><constant>DTV_MODULATION</constant></link></para></listitem> <listitem><para><link linkend="DTV-BANDWIDTH-HZ"><constant>DTV_BANDWIDTH_HZ</constant></link></para></listitem> </itemizedlist> + <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para> </section> <section id="atscmh-params"> <title>ATSC-MH delivery system</title>
@@ -988,6 +1081,7 @@ enum fe_interleaving { <listitem><para><link linkend="DTV-ATSCMH-SCCC-CODE-MODE-C"><constant>DTV_ATSCMH_SCCC_CODE_MODE_C</constant></link></para></listitem> <listitem><para><link linkend="DTV-ATSCMH-SCCC-CODE-MODE-D"><constant>DTV_ATSCMH_SCCC_CODE_MODE_D</constant></link></para></listitem> </itemizedlist> + <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para> </section> <section id="dtmb-params"> <title>DTMB delivery system</title>
@@ -1007,6 +1101,7 @@ enum fe_interleaving { <listitem><para><link linkend="DTV-INTERLEAVING"><constant>DTV_INTERLEAVING</constant></link></para></listitem> <listitem><para><link linkend="DTV-LNA"><constant>DTV_LNA</constant></link></para></listitem> </itemizedlist> + <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para> </section> </section> <section id="frontend-property-cable-systems">
@@ -1028,6 +1123,7 @@ enum fe_interleaving { <listitem><para><link linkend="DTV-INNER-FEC"><constant>DTV_INNER_FEC</constant></link></para></listitem> <listitem><para><link linkend="DTV-LNA"><constant>DTV_LNA</constant></link></para></listitem> </itemizedlist> + <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para> </section> <section id="dvbc-annex-b-params"> <title>DVB-C Annex B delivery system</title>
@@ -1043,6 +1139,7 @@ enum fe_interleaving { <listitem><para><link linkend="DTV-INVERSION"><constant>DTV_INVERSION</constant></link></para></listitem> <listitem><para><link linkend="DTV-LNA"><constant>DTV_LNA</constant></link></para></listitem> </itemizedlist> + <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para> </section> </section> <section id="frontend-property-satellital-systems">
@@ -1062,6 +1159,7 @@ enum fe_interleaving { <listitem><para><link linkend="DTV-VOLTAGE"><constant>DTV_VOLTAGE</constant></link></para></listitem> <listitem><para><link linkend="DTV-TONE"><constant>DTV_TONE</constant></link></para></listitem> </itemizedlist> + <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para> <para>Future implementations might add those two missing parameters:</para> <itemizedlist mark='opencircle'> <listitem><para><link linkend="DTV-DISEQC-MASTER"><constant>DTV_DISEQC_MASTER</constant></link></para></listitem>
@@ -1077,6 +1175,7 @@ enum fe_interleaving { <listitem><para><link linkend="DTV-ROLLOFF"><constant>DTV_ROLLOFF</constant></link></para></listitem> <listitem><para><link linkend="DTV-STREAM-ID"><constant>DTV_STREAM_ID</constant></link></para></listitem> </itemizedlist> + <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para> </section> <section id="turbo-params"> <title>Turbo code delivery system</title>
include/uapi/linux/dvb/frontend.h +76 -1
94 lines not on this page · raw message
Signature · 1 line
1.7.11.7
RFC PATCH v11 3/16 dvb: the core logic to handle the DVBv5 QoS properties
In reply to Mauro Carvalho ChehabAdd the logic to poll, reset counters and report the QoS stats to the end user.
The idea is that the core will periodically poll the frontend for the stats. The frontend may return -EBUSY, if the previous collect didn't finish, or it may fill the cached data.
The value returned to the end user is always the cached data.
--- drivers/media/dvb-core/dvb_frontend.c | 27 +++++++++++++++++++++++++++ drivers/media/dvb-core/dvb_frontend.h | 8 ++++++++ 2 files changed, 35 insertions(+)
drivers/media/dvb-core/dvb_frontend.c +27 -0
@@ -1053,6 +1053,14 @@ static struct dtv_cmds_h dtv_cmds[DTV_MAX_COMMAND + 1] = {_DTV_CMD (DTV_ATSCMH_SCCC_CODE_MODE_B ,0 ,0 ),_DTV_CMD (DTV_ATSCMH_SCCC_CODE_MODE_C ,0 ,0 ),_DTV_CMD (DTV_ATSCMH_SCCC_CODE_MODE_D ,0 ,0 ), + +/* Statistics API */ +_DTV_CMD (DTV_STAT_SIGNAL_STRENGTH ,0 ,0 ), +_DTV_CMD (DTV_STAT_CNR ,0 ,0 ), +_DTV_CMD (DTV_STAT_BIT_ERROR_COUNT ,0 ,0 ), +_DTV_CMD (DTV_STAT_TOTAL_BITS_COUNT ,0 ,0 ), +_DTV_CMD (DTV_STAT_ERROR_BLOCK_COUNT ,0 ,0 ), + _DTV_CMD(DTV_STAT_TOTAL_BLOCKS_COUNT, 0, 0), };static void dtv_property_dump (struct dvb_frontend *fe,struct dtv_property *tvp)
@@ -1443,6 +1451,25 @@ static int dtv_property_process_get(struct dvb_frontend *fe, tvp->u.data = c->lna;break ; +/* Fill quality measures */ +case DTV_STAT_SIGNAL_STRENGTH : + tvp->u.st = c->strength; +break ; +case DTV_STAT_CNR : + tvp->u.st = c->cnr; +break ; +case DTV_STAT_BIT_ERROR_COUNT : + tvp->u.st = c->bit_error; +break ; +case DTV_STAT_TOTAL_BITS_COUNT : + tvp->u.st = c->bit_count; +break ; +case DTV_STAT_ERROR_BLOCK_COUNT : + tvp->u.st = c->block_error; +break ; +case DTV_STAT_TOTAL_BLOCKS_COUNT : + tvp->u.st = c->block_count; +break ;default :return -EINVAL ; }
drivers/media/dvb-core/dvb_frontend.h +8 -0
@@ -393,6 +393,14 @@ struct dtv_frontend_properties {u8 atscmh_sccc_code_mode_d;u32 lna; + +/* statistics data */ +struct dtv_fe_stats strength; +struct dtv_fe_stats cnr; +struct dtv_fe_stats bit_error; +struct dtv_fe_stats bit_count; +struct dtv_fe_stats block_error; +struct dtv_fe_stats block_count; };struct dvb_frontend {
Signature · 1 line
1.7.11.7
RFC PATCH v11 4/16 mb86a20s: Add DVBv5 statistics at FE read_status
In reply to Mauro Carvalho ChehabInstead of providing separate callbacks to read the several FE status properties, the better seems to use just one method that will:
- Read lock status;
- Read signal strength;
- if locked, get TMCC data;
- if locked, get DVB status.
As the DVB frontend thread will call this method on every 3 seconds, all stats data will be updated together, with is a good thing. It also prevents userspace to generate undesired I2C traffic.
--- drivers/media/dvb-frontends/mb86a20s.c | 384 +++++++++++++++++++++++++++++---- 1 file changed, 348 insertions(+), 36 deletions(-)
drivers/media/dvb-frontends/mb86a20s.c +348 -36
@@ -43,6 +43,12 @@ struct mb86a20s_state {struct dvb_frontend frontend;bool need_init; + +/* +* Stats measure flags to be used to know when it is possible to +* artificially generate a "global" measure, based on all 3 layers +*/ +bool read_ber[3 ]; };struct regdata {
@@ -92,7 +98,7 @@ static struct regdata mb86a20s_init[] = { { 0x04, 0x13 }, { 0x05, 0xff }, { 0x04, 0x15 }, { 0x05, 0x4e }, { 0x04, 0x16 }, { 0x05, 0x20 }, - { 0x52, 0x01 }, + { 0x52, 0x01 }, /* Turn on BER before Viterbi */ { 0x50, 0xa7 }, { 0x51, 0xff }, { 0x50, 0xa8 }, { 0x51, 0xff }, { 0x50, 0xa9 }, { 0x51, 0xff },
@@ -117,8 +123,8 @@ static struct regdata mb86a20s_init[] = { { 0x50, 0xb6 }, { 0x51, 0xff }, { 0x50, 0xb7 }, { 0x51, 0xff }, { 0x50, 0x50 }, { 0x51, 0x02 }, - { 0x50, 0x51 }, { 0x51, 0x04 }, - { 0x45, 0x04 }, + { 0x50, 0x51 }, { 0x51, 0x04 }, /* MER symbol 4 */ + { 0x45, 0x04 }, /* CN symbol 4 */ { 0x48, 0x04 }, { 0x50, 0xd5 }, { 0x51, 0x01 }, /* Serial */ { 0x50, 0xd6 }, { 0x51, 0x1f },
@@ -174,6 +180,20 @@ static struct regdata mb86a20s_reset_reception[] = { { 0x08, 0x00 }, }; +static struct regdata mb86a20s_vber_reset[] = { + {0x53 ,0x00 },/* VBER Counter reset */ + {0x53 ,0x07 }, +}; + +static struct regdata mb86a20s_clear_stats[] = { + {0x5f ,0x00 },/* SBER Counter reset */ + {0x5f ,0x07 }, + + {0x50 ,0xb1 },/* PBER Counter reset */ + {0x51 ,0x07 }, + {0x51 ,0x01 }, +}; +static int mb86a20s_i2c_writereg (struct mb86a20s_state *state,u8 i2c_addr,int reg,int data) {
@@ -221,7 +241,7 @@ static int mb86a20s_i2c_readreg(struct mb86a20s_state *state,if (rc !=2 ) {rc ("%s: reg=0x%x (error=%d)\n" , __func__, reg, rc); -return rc; +return (rc <0 ) ? rc : -EIO ; }return val;
@@ -276,59 +296,61 @@ err:return rc; } -static int mb86a20s_read_signal_strength (struct dvb_frontend *fe,u16 *strength) +static int mb86a20s_read_signal_strength (struct dvb_frontend *fe) {struct mb86a20s_state *state = fe->demodulator_priv; +int rc;unsigned rf_max, rf_min, rf; -u8 val; - -dprintk ("\n" ); - -if (fe->ops.i2c_gate_ctrl) - fe->ops.i2c_gate_ctrl (fe,0 );/* Does a binary search to get RF strength */ rf_max =0xfff ; rf_min =0 ;do { rf = (rf_max + rf_min) /2 ; -mb86a20s_writereg (state,0x04 ,0x1f ); -mb86a20s_writereg (state,0x05 , rf >>8 ); -mb86a20s_writereg (state,0x04 ,0x20 ); -mb86a20s_writereg (state,0x04 , rf); + rc =mb86a20s_writereg (state,0x04 ,0x1f ); +if (rc <0 ) +return rc; + rc =mb86a20s_writereg (state,0x05 , rf >>8 ); +if (rc <0 ) +return rc; + rc =mb86a20s_writereg (state,0x04 ,0x20 ); +if (rc <0 ) +return rc; + rc =mb86a20s_writereg (state,0x04 , rf); +if (rc <0 ) +return rc; - val =mb86a20s_readreg (state,0x02 ); -if (val &0x08 ) + rc =mb86a20s_readreg (state,0x02 ); +if (rc <0 ) +return rc; +if (rc &0x08 ) rf_min = (rf_max + rf_min) /2 ;else rf_max = (rf_max + rf_min) /2 ;if (rf_max - rf_min <4 ) { - *strength = (((rf_max + rf_min) /2 ) *65535 ) /4095 ; -break ; + rf = (rf_max + rf_min) /2 ; + +/* Rescale it from 2^12 (4096) to 2^16 */ + rf <<= (16 -12 ); +dprintk ("signal strength = %d\n" , rf); +return rf; } }while (1 ); -dprintk ("signal strength = %d\n" , *strength); - -if (fe->ops.i2c_gate_ctrl) - fe->ops.i2c_gate_ctrl (fe,1 ); -return 0 ; }static int mb86a20s_read_status (struct dvb_frontend *fe,fe_status_t *status) {struct mb86a20s_state *state = fe->demodulator_priv; -u8 val; +int val;dprintk ("\n" ); *status =0 ; -if (fe->ops.i2c_gate_ctrl) - fe->ops.i2c_gate_ctrl (fe,0 ); val =mb86a20s_readreg (state,0x0a ) &0xf ; -if (fe->ops.i2c_gate_ctrl) - fe->ops.i2c_gate_ctrl (fe,1 ); +if (val <0 ) +return val;if (val >=2 ) *status |=FE_HAS_SIGNAL ;
@@ -350,6 +372,8 @@ static int mb86a20s_read_status(struct dvb_frontend *fe, fe_status_t *status)return 0 ; } +static int mb86a20s_reset_counters (struct dvb_frontend *fe); +static int mb86a20s_set_frontend (struct dvb_frontend *fe) {struct mb86a20s_state *state = fe->demodulator_priv;
@@ -387,6 +411,8 @@ static int mb86a20s_set_frontend(struct dvb_frontend *fe)if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl (fe,1 ); +mb86a20s_reset_counters (fe); +return rc; }
@@ -530,9 +556,6 @@ static int mb86a20s_get_frontend(struct dvb_frontend *fe)/* Reset frontend cache to default values */ mb86a20s_reset_frontend_cache (fe); -if (fe->ops.i2c_gate_ctrl) - fe->ops.i2c_gate_ctrl (fe,0 ); -/* Check for partial reception */ rc =mb86a20s_writereg (state,0x6d ,0x85 );if (rc <0 )
@@ -609,15 +632,305 @@ static int mb86a20s_get_frontend(struct dvb_frontend *fe)break ; } } +return 0 ; error: +/* per-layer info is incomplete; discard all per-layer */ + c->isdbt_layer_enabled =0 ; + +return rc; +} + +static int mb86a20s_reset_counters (struct dvb_frontend *fe) +{ +struct mb86a20s_state *state = fe->demodulator_priv; +struct dtv_frontend_properties *c = &fe->dtv_property_cache; +int rc, val, i; + +if (fe->ops.i2c_gate_ctrl) + fe->ops.i2c_gate_ctrl (fe,0 ); + +/* Reset the counters */ +memset (&c->strength,0 ,sizeof (c->strength)); +memset (&c->cnr,0 ,sizeof (c->cnr)); +memset (&c->bit_error,0 ,sizeof (c->bit_error)); +memset (&c->bit_count,0 ,sizeof (c->bit_count)); +memset (&c->block_error,0 ,sizeof (c->block_error)); +memset (&c->block_count,0 ,sizeof (c->block_count)); + +/* Clear status for most stats */ + +/* BER counter reset */ + rc =mb86a20s_writeregdata (state, mb86a20s_vber_reset); +if (rc <0 ) + goto err; +for (i =0 ; i <3 ; i++) + state->read_ber[i] = true; + +/* MER, PER counter reset */ + rc =mb86a20s_writeregdata (state, mb86a20s_clear_stats); +if (rc <0 ) + goto err; + +/* CNR counter reset */ + rc =mb86a20s_readreg (state,0x45 ); +if (rc <0 ) + goto err; + val = rc; + rc =mb86a20s_writereg (state,0x45 , val |0x10 ); +if (rc <0 ) + goto err; + rc =mb86a20s_writereg (state,0x45 , val &0x6f ); +if (rc <0 ) + goto err; + +/* MER counter reset */ + rc =mb86a20s_writereg (state,0x50 ,0x50 ); +if (rc <0 ) + goto err; + rc =mb86a20s_readreg (state,0x51 ); +if (rc <0 ) + goto err; + val = rc; + rc =mb86a20s_writereg (state,0x51 , val |0x01 ); +if (rc <0 ) + goto err; + rc =mb86a20s_writereg (state,0x51 , val &0x06 ); +if (rc <0 ) + goto err; + +err:if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl (fe,1 );return rc; +} + +static int mb86a20s_get_ber_before_vterbi (struct dvb_frontend *fe, +unsigned layer, +u32 *error,u32 *count) +{ +struct mb86a20s_state *state = fe->demodulator_priv; +u8 byte[3 ]; +int rc; +if (layer >=3 ) +return -EINVAL ; + +/* Check if the BER measures are already available */ + rc =mb86a20s_readreg (state,0x54 ); +if (rc <0 ) +return rc; + +/* Check if data is available for that layer */ +if (!(rc & (1 << layer))) +return -EBUSY ; + +/* Read Bit Error Count */ + rc =mb86a20s_readreg (state,0x55 + layer *3 ); +if (rc <0 ) +return rc; + byte[0 ] = rc; + rc =mb86a20s_readreg (state,0x56 + layer *3 ); +if (rc <0 ) +return rc; + byte[1 ] = rc; + rc =mb86a20s_readreg (state,0x57 + layer *3 ); +if (rc <0 ) +return rc; + byte[2 ] = rc; + *error = byte[0 ] <<16 | byte[1 ] <<8 | byte[2 ]; + +/* Read Bit Count */ + rc =mb86a20s_writereg (state,0x50 ,0xa7 + layer *3 ); +if (rc <0 ) +return rc; + rc =mb86a20s_readreg (state,0x51 ); +if (rc <0 ) +return rc; + byte[0 ] = rc; + rc =mb86a20s_writereg (state,0x50 ,0xa8 + layer *3 ); +if (rc <0 ) +return rc; + rc =mb86a20s_readreg (state,0x51 ); +if (rc <0 ) +return rc; + byte[1 ] = rc; + rc =mb86a20s_writereg (state,0x50 ,0xa9 + layer *3 ); +if (rc <0 ) +return rc; + rc =mb86a20s_readreg (state,0x51 ); +if (rc <0 ) +return rc; + byte[2 ] = rc; + *count = byte[0 ] <<16 | byte[1 ] <<8 | byte[2 ]; + +return rc; +} + +static void mb86a20s_stats_not_ready (struct dvb_frontend *fe) +{ +struct dtv_frontend_properties *c = &fe->dtv_property_cache; +int i; + +/* Fill the length of each status counter */ + +/* Only global stats */ + c->strength.len =1 ; + +/* Per-layer stats - 3 layers + global */ + c->cnr.len =4 ; + c->bit_error.len =4 ; + c->bit_count.len =4 ; + c->block_error.len =4 ; + c->block_count.len =4 ; + +/* Signal is always available */ + c->strength.stat[0 ].scale =FE_SCALE_RELATIVE ; + c->strength.stat[0 ].uvalue =0 ; + +/* Put all of them at FE_SCALE_NOT_AVAILABLE */ +for (i =0 ; i <4 ; i++) { + c->cnr.stat[i].scale =FE_SCALE_NOT_AVAILABLE ; + c->bit_error.stat[i].scale =FE_SCALE_NOT_AVAILABLE ; + c->bit_count.stat[i].scale =FE_SCALE_NOT_AVAILABLE ; + c->block_error.stat[i].scale =FE_SCALE_NOT_AVAILABLE ; + c->block_count.stat[i].scale =FE_SCALE_NOT_AVAILABLE ; + } } +static int mb86a20s_get_stats (struct dvb_frontend *fe) +{ +struct mb86a20s_state *state = fe->demodulator_priv; +struct dtv_frontend_properties *c = &fe->dtv_property_cache; +int rc =0 , i; +u32 bit_error =0 , bit_count =0 ; +u32 t_bit_error =0 , t_bit_count =0 ; +int active_layers =0 , ber_layers =0 ; + +/* Get per-layer stats */ +for (i =0 ; i <3 ; i++) { +if (c->isdbt_layer_enabled & (1 << i)) { +/* Layer is active and has rc segments */ + active_layers++; + +if (state->read_ber[i]) { +/* Handle BER before vterbi */ + rc =mb86a20s_get_ber_before_vterbi (fe, i, + &bit_error, + &bit_count); +if (rc >=0 ) { + c->bit_error.stat[1 + i].scale =FE_SCALE_COUNTER ; + c->bit_error.stat[1 + i].uvalue += bit_error; + c->bit_count.stat[1 + i].scale =FE_SCALE_COUNTER ; + c->bit_count.stat[1 + i].uvalue += bit_count; + + state->read_ber[i] = false; + }else if (rc != -EBUSY ) { +/* +* If an I/O error happened, +* measures are now unavailable +*/ + c->bit_error.stat[1 + i].scale =FE_SCALE_NOT_AVAILABLE ; + c->bit_count.stat[1 + i].scale =FE_SCALE_NOT_AVAILABLE ; + } + } +if (!state->read_ber[i]) { +/* Update total BER counter */ + t_bit_error += c->bit_error.stat[1 + i].uvalue; + t_bit_count += c->bit_count.stat[1 + i].uvalue; + + ber_layers++; + } + } + } + +if (active_layers == ber_layers) { +/* +* All BER values are read. We can now calculate the total BER +* And ask for another BER measure +* +* Total Bit Error/Count is calculated as the sum of the +* bit errors on all active layers. +*/ + c->bit_error.stat[0 ].scale =FE_SCALE_COUNTER ; + c->bit_error.stat[0 ].uvalue += t_bit_error; + c->bit_count.stat[0 ].scale =FE_SCALE_COUNTER ; + c->bit_count.stat[0 ].uvalue += t_bit_count; + +/* Reset counters to collect new data */ + rc =mb86a20s_writeregdata (state, mb86a20s_vber_reset); + +/* All BER measures need to be collected when ready */ +for (i =0 ; i <3 ; i++) + state->read_ber[i] = true; + } +return rc; +} + +static int mb86a20s_read_status_and_stats (struct dvb_frontend *fe, +fe_status_t *status) +{ +struct dtv_frontend_properties *c = &fe->dtv_property_cache; +int rc; + +if (fe->ops.i2c_gate_ctrl) + fe->ops.i2c_gate_ctrl (fe,0 ); + +/* Get lock */ + rc =mb86a20s_read_status (fe, status); +if (!(*status &FE_HAS_LOCK )) { +mb86a20s_stats_not_ready (fe); +mb86a20s_reset_frontend_cache (fe); + } +if (rc <0 ) + goto error; + +/* Get signal strength */ + rc =mb86a20s_read_signal_strength (fe); +if (rc <0 ) { +mb86a20s_stats_not_ready (fe); +mb86a20s_reset_frontend_cache (fe); + goto error; + } +/* Fill signal strength */ + c->strength.stat[0 ].uvalue = rc; + +if (*status &FE_HAS_LOCK ) { +/* Get TMCC info*/ + rc =mb86a20s_get_frontend (fe); +if (rc <0 ) + goto error; + +/* Get statistics */ + rc =mb86a20s_get_stats (fe); +if (rc <0 ) + goto error; + } + goto ok; + +error: +mb86a20s_stats_not_ready (fe); + +ok: +if (fe->ops.i2c_gate_ctrl) + fe->ops.i2c_gate_ctrl (fe,1 ); + +return rc; +} + +static int mb86a20s_read_signal_strength_from_cache (struct dvb_frontend *fe, +u16 *strength) +{ +struct dtv_frontend_properties *c = &fe->dtv_property_cache; + + + *strength = c->strength.stat[0 ].uvalue; + +return 0 ; +} + + static int mb86a20s_tune(struct dvb_frontend *fe, bool re_tune, unsigned int mode_flags,
@@ -632,7 +945,7 @@ static int mb86a20s_tune(struct dvb_frontend *fe, rc =mb86a20s_set_frontend (fe);if (!(mode_flags &FE_TUNE_MODE_ONESHOT )) -mb86a20s_read_status (fe, status); +mb86a20s_read_status_and_stats (fe, status);return rc; }
@@ -712,9 +1025,8 @@ static struct dvb_frontend_ops mb86a20s_ops = { .init = mb86a20s_initfe, .set_frontend = mb86a20s_set_frontend, - .get_frontend = mb86a20s_get_frontend, - .read_status = mb86a20s_read_status, - .read_signal_strength = mb86a20s_read_signal_strength, + .read_status = mb86a20s_read_status_and_stats, + .read_signal_strength = mb86a20s_read_signal_strength_from_cache, .tune = mb86a20s_tune, };
Signature · 1 line
1.7.11.7
RFC PATCH v11 5/16 mb86a20s: functions reorder
In reply to Mauro Carvalho ChehabNo functional changes here. Just re-organizes the functions inside the file.
--- drivers/media/dvb-frontends/mb86a20s.c | 223 +++++++++++++++++---------------- 1 file changed, 118 insertions(+), 105 deletions(-)
drivers/media/dvb-frontends/mb86a20s.c +118 -105
@@ -194,6 +194,10 @@ static struct regdata mb86a20s_clear_stats[] = { { 0x51, 0x01 }, }; +/* +* I2C read/write functions and macros +*/ +static int mb86a20s_i2c_writereg (struct mb86a20s_state *state,u8 i2c_addr,int reg,int data) {
@@ -255,45 +259,42 @@ static int mb86a20s_i2c_readreg(struct mb86a20s_state *state,mb86a20s_i2c_writeregdata (state, state->config->demod_address, \ regdata,ARRAY_SIZE (regdata)) -static int mb86a20s_initfe (struct dvb_frontend *fe) +/* +* Ancillary internal routines (likely compiled inlined) +* +* The functions below assume that gateway lock has already obtained + */ + +static int mb86a20s_read_status (struct dvb_frontend *fe,fe_status_t *status) {struct mb86a20s_state *state = fe->demodulator_priv; -int rc; -u8 regD5 =1 ; +int val;dprintk ("\n" ); + *status =0 ; -if (fe->ops.i2c_gate_ctrl) - fe->ops.i2c_gate_ctrl (fe,0 ); + val =mb86a20s_readreg (state,0x0a ) &0xf ; +if (val <0 ) +return val; -/* Initialize the frontend */ - rc =mb86a20s_writeregdata (state, mb86a20s_init); -if (rc <0 ) - goto err; +if (val >=2 ) + *status |=FE_HAS_SIGNAL ; -if (!state->config->is_serial) { - regD5 &= ~1 ; +if (val >=4 ) + *status |=FE_HAS_CARRIER ; - rc =mb86a20s_writereg (state,0x50 ,0xd5 ); -if (rc <0 ) - goto err; - rc =mb86a20s_writereg (state,0x51 , regD5); -if (rc <0 ) - goto err; - } +if (val >=5 ) + *status |=FE_HAS_VITERBI ; -if (fe->ops.i2c_gate_ctrl) - fe->ops.i2c_gate_ctrl (fe,1 ); +if (val >=7 ) + *status |=FE_HAS_SYNC ; -err: -if (rc <0 ) { - state->need_init = true; -printk (KERN_INFO "mb86a20s: Init failed. Will try again later\n" ); - }else { - state->need_init = false; -dprintk ("Initialization succeeded.\n" ); - } -return rc; +if (val >=8 )/* Maybe 9? */ + *status |=FE_HAS_LOCK ; + +dprintk ("val = %d, status = 0x%02x\n" , val, *status); + +return 0 ; }static int mb86a20s_read_signal_strength (struct dvb_frontend *fe)
@@ -340,82 +341,6 @@ static int mb86a20s_read_signal_strength(struct dvb_frontend *fe)return 0 ; } -static int mb86a20s_read_status (struct dvb_frontend *fe,fe_status_t *status) -{ -struct mb86a20s_state *state = fe->demodulator_priv; -int val; - -dprintk ("\n" ); - *status =0 ; - - val =mb86a20s_readreg (state,0x0a ) &0xf ; -if (val <0 ) -return val; - -if (val >=2 ) - *status |=FE_HAS_SIGNAL ; - -if (val >=4 ) - *status |=FE_HAS_CARRIER ; - -if (val >=5 ) - *status |=FE_HAS_VITERBI ; - -if (val >=7 ) - *status |=FE_HAS_SYNC ; - -if (val >=8 )/* Maybe 9? */ - *status |=FE_HAS_LOCK ; - -dprintk ("val = %d, status = 0x%02x\n" , val, *status); - -return 0 ; -} - -static int mb86a20s_reset_counters (struct dvb_frontend *fe); - -static int mb86a20s_set_frontend (struct dvb_frontend *fe) -{ -struct mb86a20s_state *state = fe->demodulator_priv; -int rc; -#if 0 -/* -* FIXME: Properly implement the set frontend properties -*/ -struct dtv_frontend_properties *c = &fe->dtv_property_cache; -#endif - -dprintk ("\n" ); - -if (fe->ops.i2c_gate_ctrl) - fe->ops.i2c_gate_ctrl (fe,1 ); -dprintk ("Calling tuner set parameters\n" ); - fe->ops.tuner_ops.set_params (fe); - -/* -* Make it more reliable: if, for some reason, the initial -* device initialization doesn't happen, initialize it when -* a SBTVD parameters are adjusted. -* -* Unfortunately, due to a hard to track bug at tda829x/tda18271, -* the agc callback logic is not called during DVB attach time, -* causing mb86a20s to not be initialized with Kworld SBTVD. -* So, this hack is needed, in order to make Kworld SBTVD to work. -*/ -if (state->need_init) -mb86a20s_initfe (fe); - -if (fe->ops.i2c_gate_ctrl) - fe->ops.i2c_gate_ctrl (fe,0 ); - rc =mb86a20s_writeregdata (state, mb86a20s_reset_reception); -if (fe->ops.i2c_gate_ctrl) - fe->ops.i2c_gate_ctrl (fe,1 ); - -mb86a20s_reset_counters (fe); - -return rc; -} -static int mb86a20s_get_modulation (struct mb86a20s_state *state,unsigned layer) {
@@ -868,6 +793,94 @@ static int mb86a20s_get_stats(struct dvb_frontend *fe)return rc; } +/* +* The functions below are called via DVB callbacks, so they need to +* properly use the I2C gate control +*/ + +static int mb86a20s_initfe (struct dvb_frontend *fe) +{ +struct mb86a20s_state *state = fe->demodulator_priv; +int rc; +u8 regD5 =1 ; + +dprintk ("\n" ); + +if (fe->ops.i2c_gate_ctrl) + fe->ops.i2c_gate_ctrl (fe,0 ); + +/* Initialize the frontend */ + rc =mb86a20s_writeregdata (state, mb86a20s_init); +if (rc <0 ) + goto err; + +if (!state->config->is_serial) { + regD5 &= ~1 ; + + rc =mb86a20s_writereg (state,0x50 ,0xd5 ); +if (rc <0 ) + goto err; + rc =mb86a20s_writereg (state,0x51 , regD5); +if (rc <0 ) + goto err; + } + +if (fe->ops.i2c_gate_ctrl) + fe->ops.i2c_gate_ctrl (fe,1 ); + +err: +if (rc <0 ) { + state->need_init = true; +printk (KERN_INFO "mb86a20s: Init failed. Will try again later\n" ); + }else { + state->need_init = false; +dprintk ("Initialization succeeded.\n" ); + } +return rc; +} + +static int mb86a20s_set_frontend (struct dvb_frontend *fe) +{ +struct mb86a20s_state *state = fe->demodulator_priv; +int rc; +#if 0 +/* +* FIXME: Properly implement the set frontend properties +*/ +struct dtv_frontend_properties *c = &fe->dtv_property_cache; +#endif + +dprintk ("\n" ); + +if (fe->ops.i2c_gate_ctrl) + fe->ops.i2c_gate_ctrl (fe,1 ); +dprintk ("Calling tuner set parameters\n" ); + fe->ops.tuner_ops.set_params (fe); + +/* +* Make it more reliable: if, for some reason, the initial +* device initialization doesn't happen, initialize it when +* a SBTVD parameters are adjusted. +* +* Unfortunately, due to a hard to track bug at tda829x/tda18271, +* the agc callback logic is not called during DVB attach time, +* causing mb86a20s to not be initialized with Kworld SBTVD. +* So, this hack is needed, in order to make Kworld SBTVD to work. +*/ +if (state->need_init) +mb86a20s_initfe (fe); + +if (fe->ops.i2c_gate_ctrl) + fe->ops.i2c_gate_ctrl (fe,0 ); + rc =mb86a20s_writeregdata (state, mb86a20s_reset_reception); +if (fe->ops.i2c_gate_ctrl) + fe->ops.i2c_gate_ctrl (fe,1 ); + +mb86a20s_reset_counters (fe); + +return rc; +} +static int mb86a20s_read_status_and_stats (struct dvb_frontend *fe,fe_status_t *status) {
Signature · 1 line
1.7.11.7
RFC PATCH v11 6/16 mb86a20s: Fix i2c gate on error
In reply to Mauro Carvalho ChehabIf an error happens, restore tuner I2C gate to the right value.
--- drivers/media/dvb-frontends/mb86a20s.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/dvb-frontends/mb86a20s.c +5 -1
@@ -825,10 +825,10 @@ static int mb86a20s_initfe(struct dvb_frontend *fe) goto err; } +err:if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl (fe,1 ); -err:if (rc <0 ) { state->need_init = true;printk (KERN_INFO "mb86a20s: Init failed. Will try again later\n" );
@@ -852,6 +852,10 @@ static int mb86a20s_set_frontend(struct dvb_frontend *fe)dprintk ("\n" ); +/* +* Gate should already be opened, but it doesn't hurt to +* double-check +*/ if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl (fe,1 );dprintk ("Calling tuner set parameters\n" );
Signature · 1 line
1.7.11.7
RFC PATCH v11 7/16 mb86a20s: improve debug for RF level
In reply to Mauro Carvalho Chehab--- drivers/media/dvb-frontends/mb86a20s.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/dvb-frontends/mb86a20s.c +2 -1
@@ -333,7 +333,8 @@ static int mb86a20s_read_signal_strength(struct dvb_frontend *fe)/* Rescale it from 2^12 (4096) to 2^16 */ rf <<= (16 -12 ); -dprintk ("signal strength = %d\n" , rf); +dprintk ("signal strength = %d (%d < RF=%d < %d)\n" , rf, + rf_min, rf, rf_max);return rf; } }while (1 );
Signature · 1 line
1.7.11.7
RFC PATCH v11 8/16 mb86a20s: fix interleaving and FEC retrival
In reply to Mauro Carvalho ChehabGet the proper bits from the TMCC table registers.
--- drivers/media/dvb-frontends/mb86a20s.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
drivers/media/dvb-frontends/mb86a20s.c +17 -5
@@ -360,7 +360,7 @@ static int mb86a20s_get_modulation(struct mb86a20s_state *state, rc =mb86a20s_readreg (state,0x6e );if (rc <0 )return rc; -switch ((rc &0x70 ) >>4 ) { +switch ((rc >>4 ) &0x07 ) {case 0 :return DQPSK ;case 1 :
@@ -393,7 +393,7 @@ static int mb86a20s_get_fec(struct mb86a20s_state *state, rc =mb86a20s_readreg (state,0x6e );if (rc <0 )return rc; -switch (rc) { +switch ((rc >>4 ) &0x07 ) {case 0 :return FEC_1_2 ;case 1 :
@@ -428,9 +428,21 @@ static int mb86a20s_get_interleaving(struct mb86a20s_state *state, rc =mb86a20s_readreg (state,0x6e );if (rc <0 )return rc; -if (rc >3 ) -return -EINVAL ;/* Not used */ -return rc; + +switch ((rc >>4 ) &0x07 ) { +case 1 : +return GUARD_INTERVAL_1_4 ; +case 2 : +return GUARD_INTERVAL_1_8 ; +case 3 : +return GUARD_INTERVAL_1_16 ; +case 4 : +return GUARD_INTERVAL_1_32 ; + +default : +case 0 : +return GUARD_INTERVAL_AUTO ; + } } static int mb86a20s_get_segment_count(struct mb86a20s_state *state,
Signature · 1 line
1.7.11.7
RFC PATCH v11 9/16 mb86a20s: convert it to use dev_info/dev_err/dev_dbg
In reply to Mauro Carvalho ChehabAlso add some additional debug and error messages when needed.
--- drivers/media/dvb-frontends/mb86a20s.c | 156 +++++++++++++++++++++++---------- 1 file changed, 111 insertions(+), 45 deletions(-)
drivers/media/dvb-frontends/mb86a20s.c +111 -45
@@ -24,18 +24,6 @@ static int debug = 1;module_param (debug, int,0644 );MODULE_PARM_DESC (debug,"Activates frontend debugging (default:0)" ); -#define rc(args...) do { \ - printk(KERN_ERR "mb86a20s: " args); \ -} while (0) - -#define dprintk(args...) \ - do { \ - if (debug) { \ - printk(KERN_DEBUG "mb86a20s: %s: ", __func__); \ - printk(args); \ - } \ - } while (0) -struct mb86a20s_state {struct i2c_adapter *i2c;const struct mb86a20s_config *config;
@@ -209,8 +197,9 @@ static int mb86a20s_i2c_writereg(struct mb86a20s_state *state, rc =i2c_transfer (state->i2c, &msg,1 );if (rc !=1 ) { -printk ("%s: writereg error (rc == %i, reg == 0x%02x," -" data == 0x%02x)\n" , __func__, rc, reg, data); +dev_err (&state->i2c->dev, +"%s: writereg error (rc == %i, reg == 0x%02x, data == 0x%02x)\n" , + __func__, rc, reg, data);return rc; }
@@ -244,7 +233,8 @@ static int mb86a20s_i2c_readreg(struct mb86a20s_state *state, rc =i2c_transfer (state->i2c, msg,2 );if (rc !=2 ) { -rc ("%s: reg=0x%x (error=%d)\n" , __func__, reg, rc); +dev_err (&state->i2c->dev,"%s: reg=0x%x (error=%d)\n" , + __func__, reg, rc);return (rc <0 ) ? rc : -EIO ; }
@@ -270,7 +260,6 @@ static int mb86a20s_read_status(struct dvb_frontend *fe, fe_status_t *status)struct mb86a20s_state *state = fe->demodulator_priv;int val; -dprintk ("\n" ); *status =0 ; val =mb86a20s_readreg (state,0x0a ) &0xf ;
@@ -292,7 +281,8 @@ static int mb86a20s_read_status(struct dvb_frontend *fe, fe_status_t *status)if (val >=8 )/* Maybe 9? */ *status |=FE_HAS_LOCK ; -dprintk ("val = %d, status = 0x%02x\n" , val, *status); +dev_dbg (&state->i2c->dev,"%s: Status = 0x%02x (state = %d)\n" , + __func__, *status, val);return 0 ; }
@@ -333,8 +323,9 @@ static int mb86a20s_read_signal_strength(struct dvb_frontend *fe)/* Rescale it from 2^12 (4096) to 2^16 */ rf <<= (16 -12 ); -dprintk ("signal strength = %d (%d < RF=%d < %d)\n" , rf, - rf_min, rf, rf_max); +dev_dbg (&state->i2c->dev, +"%s: signal strength = %d (%d < RF=%d < %d)\n" , + __func__, rf, rf_min, rf >>4 , rf_max);return rf; } }while (1 );
@@ -449,15 +440,17 @@ static int mb86a20s_get_segment_count(struct mb86a20s_state *state, unsigned layer) {int rc, count; -static unsigned char reg[] = { [0 ] =0x89 ,/* Layer A */ [1 ] =0x8d ,/* Layer B */ [2 ] =0x91 ,/* Layer C */ }; +dev_dbg (&state->i2c->dev,"%s called.\n" , __func__); +if (layer >=ARRAY_SIZE (reg))return -EINVAL ; + rc =mb86a20s_writereg (state,0x6d , reg[layer]);if (rc <0 )return rc;
@@ -466,13 +459,18 @@ static int mb86a20s_get_segment_count(struct mb86a20s_state *state,return rc; count = (rc >>4 ) &0x0f ; +dev_dbg (&state->i2c->dev,"%s: segments: %d.\n" , __func__, count); +return count; }static void mb86a20s_reset_frontend_cache (struct dvb_frontend *fe) { +struct mb86a20s_state *state = fe->demodulator_priv;struct dtv_frontend_properties *c = &fe->dtv_property_cache; +dev_dbg (&state->i2c->dev,"%s called.\n" , __func__); +/* Fixed parameters */ c->delivery_system =SYS_ISDBT ; c->bandwidth_hz =6000000 ;
@@ -491,6 +489,8 @@ static int mb86a20s_get_frontend(struct dvb_frontend *fe)struct dtv_frontend_properties *c = &fe->dtv_property_cache;int i, rc; +dev_dbg (&state->i2c->dev,"%s called.\n" , __func__); +/* Reset frontend cache to default values */ mb86a20s_reset_frontend_cache (fe);
@@ -506,9 +506,12 @@ static int mb86a20s_get_frontend(struct dvb_frontend *fe)/* Get per-layer data */ for (i =0 ; i <3 ; i++) { +dev_dbg (&state->i2c->dev,"%s: getting data for layer %c.\n" , + __func__,'A' + i); + rc =mb86a20s_get_segment_count (state, i);if (rc <0 ) - goto error; + goto noperlayer_error;if (rc >=0 && rc <14 ) c->layer[i].segment_count = rc;else {
@@ -518,15 +521,21 @@ static int mb86a20s_get_frontend(struct dvb_frontend *fe) c->isdbt_layer_enabled |=1 << i; rc =mb86a20s_get_modulation (state, i);if (rc <0 ) - goto error; + goto noperlayer_error; +dev_dbg (&state->i2c->dev,"%s: modulation %d.\n" , + __func__, rc); c->layer[i].modulation = rc; rc =mb86a20s_get_fec (state, i);if (rc <0 ) - goto error; + goto noperlayer_error; +dev_dbg (&state->i2c->dev,"%s: FEC %d.\n" , + __func__, rc); c->layer[i].fec = rc; rc =mb86a20s_get_interleaving (state, i);if (rc <0 ) - goto error; + goto noperlayer_error; +dev_dbg (&state->i2c->dev,"%s: interleaving %d.\n" , + __func__, rc); c->layer[i].interleaving = rc; }
@@ -572,7 +581,8 @@ static int mb86a20s_get_frontend(struct dvb_frontend *fe) }return 0 ; -error: +noperlayer_error: +/* per-layer info is incomplete; discard all per-layer */ c->isdbt_layer_enabled =0 ;
@@ -585,6 +595,8 @@ static int mb86a20s_reset_counters(struct dvb_frontend *fe)struct dtv_frontend_properties *c = &fe->dtv_property_cache;int rc, val, i; +dev_dbg (&state->i2c->dev,"%s called.\n" , __func__); +if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl (fe,0 );
@@ -637,7 +649,12 @@ static int mb86a20s_reset_counters(struct dvb_frontend *fe)if (rc <0 ) goto err; + goto ok; err: +dev_err (&state->i2c->dev, +"%s: Can't reset FE QoS counters (error %d).\n" , + __func__, rc); +ok:if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl (fe,1 );
@@ -652,6 +669,8 @@ static int mb86a20s_get_ber_before_vterbi(struct dvb_frontend *fe,u8 byte[3 ];int rc; +dev_dbg (&state->i2c->dev,"%s called.\n" , __func__); +if (layer >=3 )return -EINVAL ;
@@ -661,8 +680,12 @@ static int mb86a20s_get_ber_before_vterbi(struct dvb_frontend *fe,return rc;/* Check if data is available for that layer */ -if (!(rc & (1 << layer))) +if (!(rc & (1 << layer))) { +dev_info (&state->i2c->dev, +"%s: BER for layer %c is not available yet.\n" , + __func__,'A' + layer);return -EBUSY ; + }/* Read Bit Error Count */ rc =mb86a20s_readreg (state,0x55 + layer *3 );
@@ -679,6 +702,10 @@ static int mb86a20s_get_ber_before_vterbi(struct dvb_frontend *fe, byte[2 ] = rc; *error = byte[0 ] <<16 | byte[1 ] <<8 | byte[2 ]; +dev_err (&state->i2c->dev, +"%s: bit error before Viterbi for layer %c: %d.\n" , + __func__,'A' + layer, *error); +/* Read Bit Count */ rc =mb86a20s_writereg (state,0x50 ,0xa7 + layer *3 );if (rc <0 )
@@ -702,15 +729,21 @@ static int mb86a20s_get_ber_before_vterbi(struct dvb_frontend *fe,return rc; byte[2 ] = rc; *count = byte[0 ] <<16 | byte[1 ] <<8 | byte[2 ]; +dev_dbg (&state->i2c->dev, +"%s: bit count before Viterbi for layer %c: %d.\n" , + __func__,'A' + layer, *count); -return rc; +return 0 ; }static void mb86a20s_stats_not_ready (struct dvb_frontend *fe) { +struct mb86a20s_state *state = fe->demodulator_priv;struct dtv_frontend_properties *c = &fe->dtv_property_cache;int i; +dev_dbg (&state->i2c->dev,"%s called.\n" , __func__); +/* Fill the length of each status counter */ /* Only global stats */
@@ -746,6 +779,8 @@ static int mb86a20s_get_stats(struct dvb_frontend *fe)u32 t_bit_error =0 , t_bit_count =0 ;int active_layers =0 , ber_layers =0 ; +dev_dbg (&state->i2c->dev,"%s called.\n" , __func__); +/* Get per-layer stats */ for (i =0 ; i <3 ; i++) {if (c->isdbt_layer_enabled & (1 << i)) {
@@ -771,6 +806,10 @@ static int mb86a20s_get_stats(struct dvb_frontend *fe)*/ c->bit_error.stat[1 + i].scale =FE_SCALE_NOT_AVAILABLE ; c->bit_count.stat[1 + i].scale =FE_SCALE_NOT_AVAILABLE ; +dev_err (&state->i2c->dev, +"%s: Can't get BER for layer %c (error %d).\n" , + __func__,'A' + i, rc); + } }if (!state->read_ber[i]) {
@@ -798,6 +837,9 @@ static int mb86a20s_get_stats(struct dvb_frontend *fe)/* Reset counters to collect new data */ rc =mb86a20s_writeregdata (state, mb86a20s_vber_reset); +if (rc <0 ) +dev_err (&state->i2c->dev, +"%s: Can't reset VBER registers.\n" , __func__);/* All BER measures need to be collected when ready */ for (i =0 ; i <3 ; i++)
@@ -817,7 +859,7 @@ static int mb86a20s_initfe(struct dvb_frontend *fe)int rc;u8 regD5 =1 ; -dprintk ("\n" ); +dev_dbg (&state->i2c->dev,"%s called.\n" , __func__);if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl (fe,0 );
@@ -844,10 +886,11 @@ err:if (rc <0 ) { state->need_init = true; -printk (KERN_INFO "mb86a20s: Init failed. Will try again later\n" ); +dev_info (&state->i2c->dev, +"mb86a20s: Init failed. Will try again later\n" ); }else { state->need_init = false; -dprintk ("Initialization succeeded.\n" ); +dev_dbg (&state->i2c->dev,"Initialization succeeded.\n" ); }return rc; }
@@ -856,6 +899,9 @@ static int mb86a20s_set_frontend(struct dvb_frontend *fe) {struct mb86a20s_state *state = fe->demodulator_priv;int rc; + +dev_dbg (&state->i2c->dev,"%s called.\n" , __func__); +#if 0 /* * FIXME: Properly implement the set frontend properties
@@ -863,15 +909,12 @@ static int mb86a20s_set_frontend(struct dvb_frontend *fe)struct dtv_frontend_properties *c = &fe->dtv_property_cache;#endif -dprintk ("\n" ); -/* * Gate should already be opened, but it doesn't hurt to * double-check */ if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl (fe,1 ); -dprintk ("Calling tuner set parameters\n" ); fe->ops.tuner_ops.set_params (fe);/*
@@ -901,9 +944,12 @@ static int mb86a20s_set_frontend(struct dvb_frontend *fe)static int mb86a20s_read_status_and_stats (struct dvb_frontend *fe,fe_status_t *status) { +struct mb86a20s_state *state = fe->demodulator_priv;struct dtv_frontend_properties *c = &fe->dtv_property_cache;int rc; +dev_dbg (&state->i2c->dev,"%s called.\n" , __func__); +if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl (fe,0 );
@@ -913,14 +959,21 @@ static int mb86a20s_read_status_and_stats(struct dvb_frontend *fe,mb86a20s_stats_not_ready (fe);mb86a20s_reset_frontend_cache (fe); } -if (rc <0 ) +if (rc <0 ) { +dev_err (&state->i2c->dev, +"%s: Can't read frontend lock status\n" , __func__); goto error; + }/* Get signal strength */ rc =mb86a20s_read_signal_strength (fe);if (rc <0 ) { +dev_err (&state->i2c->dev, +"%s: Can't reset VBER registers.\n" , __func__);mb86a20s_stats_not_ready (fe);mb86a20s_reset_frontend_cache (fe); + + rc =0 ;/* Status is OK */ goto error; }/* Fill signal strength */
@@ -929,13 +982,21 @@ static int mb86a20s_read_status_and_stats(struct dvb_frontend *fe,if (*status &FE_HAS_LOCK ) {/* Get TMCC info*/ rc =mb86a20s_get_frontend (fe); -if (rc <0 ) +if (rc <0 ) { +dev_err (&state->i2c->dev, +"%s: Can't get FE TMCC data.\n" , __func__); + rc =0 ;/* Status is OK */ goto error; + }/* Get statistics */ rc =mb86a20s_get_stats (fe); -if (rc <0 ) +if (rc <0 ) { +dev_err (&state->i2c->dev, +"%s: Can't get FE QoS statistics.\n" , __func__); + rc =0 ; goto error; + } } goto ok;
@@ -967,9 +1028,10 @@ static int mb86a20s_tune(struct dvb_frontend *fe,unsigned int *delay, fe_status_t *status) { + struct mb86a20s_state *state = fe->demodulator_priv;int rc =0 ; -dprintk ("\n" ); +dev_dbg (&state->i2c->dev,"%s called.\n" , __func__);if (re_tune) rc =mb86a20s_set_frontend (fe);
@@ -984,7 +1046,7 @@ static void mb86a20s_release(struct dvb_frontend *fe) {struct mb86a20s_state *state = fe->demodulator_priv; -dprintk ("\n" ); +dev_dbg (&state->i2c->dev,"%s called.\n" , __func__);kfree (state); }
@@ -995,14 +1057,16 @@ struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config, struct i2c_adapter *i2c) {u8 rev; +struct mb86a20s_state *state;/* allocate memory for the internal state */ -struct mb86a20s_state *state = -kzalloc (sizeof (struct mb86a20s_state ),GFP_KERNEL ); + state =kzalloc (sizeof (struct mb86a20s_state ),GFP_KERNEL ); + +dev_dbg (&state->i2c->dev,"%s called.\n" , __func__); -dprintk ("\n" );if (state ==NULL ) { -rc ("Unable to kzalloc\n" ); +dev_err (&state->i2c->dev, +"%s: unable to allocate memory for state\n" , __func__); goto error; }
@@ -1019,10 +1083,12 @@ struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config, rev =mb86a20s_readreg (state,0 );if (rev ==0x13 ) { -printk (KERN_INFO "Detected a Fujitsu mb86a20s frontend\n" ); +dev_info (&state->i2c->dev, +"Detected a Fujitsu mb86a20s frontend\n" ); }else { -printk (KERN_ERR "Frontend revision %d is unknown - aborting.\n" , - rev); +dev_err (&state->i2c->dev, +"Frontend revision %d is unknown - aborting.\n" , + rev); goto error; }
Signature · 1 line
1.7.11.7
RFC PATCH v11 10/16 mb86a20s: -EBUSY is expected when getting stats measures
In reply to Mauro Carvalho Chehab--- drivers/media/dvb-frontends/mb86a20s.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/dvb-frontends/mb86a20s.c +2 -1
@@ -991,12 +991,13 @@ static int mb86a20s_read_status_and_stats(struct dvb_frontend *fe,/* Get statistics */ rc =mb86a20s_get_stats (fe); -if (rc <0 ) { +if (rc <0 && rc != -EBUSY ) {dev_err (&state->i2c->dev,"%s: Can't get FE QoS statistics.\n" , __func__); rc =0 ; goto error; } + rc =0 ;/* Don't return EBUSY to userspace */ } goto ok;
Signature · 1 line
1.7.11.7
RFC PATCH v11 11/16 mb86a20s: make AGC work better
In reply to Mauro Carvalho ChehabIt is recommented to change register 0x0440 value to 0, in order to fix some AGC bug.
--- drivers/media/dvb-frontends/mb86a20s.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/dvb-frontends/mb86a20s.c +2 -1
@@ -120,7 +120,8 @@ static struct regdata mb86a20s_init[] = { { 0x50, 0xd7 }, { 0x51, 0x3f }, { 0x28, 0x74 }, { 0x29, 0x00 }, { 0x28, 0x74 }, { 0x29, 0x40 }, { 0x28, 0x46 }, { 0x29, 0x2c }, { 0x28, 0x46 }, { 0x29, 0x0c }, - { 0x04, 0x40 }, { 0x05, 0x01 }, + + { 0x04, 0x40 }, { 0x05, 0x00 }, { 0x28, 0x00 }, { 0x29, 0x10 }, { 0x28, 0x05 }, { 0x29, 0x02 }, { 0x1c, 0x01 },
Signature · 1 line
1.7.11.7
RFC PATCH v11 12/16 mb86a20s: Some improvements for BER measurement
In reply to Mauro Carvalho ChehabReduce the bit count from 2^24-1 to 2^16-1 to speedup BER measurement;
Do a per-layer reset, instead of waiting for data on all layers;
Global stats now start to appear as soon as the first layer (e. g. the one with the biggest number of segments) start to have collected data.
--- drivers/media/dvb-frontends/mb86a20s.c | 52 +++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 13 deletions(-)
drivers/media/dvb-frontends/mb86a20s.c +39 -13
@@ -86,16 +86,36 @@ static struct regdata mb86a20s_init[] = { { 0x04, 0x13 }, { 0x05, 0xff }, { 0x04, 0x15 }, { 0x05, 0x4e }, { 0x04, 0x16 }, { 0x05, 0x20 }, + +/* +* On this demod, when the bit count reaches the count below, +* it collects the bit error count. +* +* As FE thread runs on every 3 seconds, adjust the counters to +* provide one collect before 3 seconds, at the worse case (DQPSK, +* 1/4 guard interval, 1/2 FEC, 1-seg rate is 280 Mbps, and +* 3 seconds takes 0xcdb9f bits. Rounds it down to 0xccfff +* +* It should be noticed, however, that, with QAM-64 1/32 guard interval, +* 1 segment bit rate is 1.78 Mbps, and 12-seg is about 21.5 Mbps. +* At such rate, the time to measure BER is about 40 ms. +* +* It makes sense to change the logic there to use TMCC parameters and +* adjust the counters in order to have all of them to take a little +* less than 3 seconds, in order to have a more realistic BER rate, +* instead of having short samples for 12-segs. +*/ { 0x52, 0x01 }, /* Turn on BER before Viterbi */ - { 0x50, 0xa7 }, { 0x51, 0xff }, - { 0x50, 0xa8 }, { 0x51, 0xff }, + { 0x50, 0xa7 }, { 0x51, 0x0c }, + { 0x50, 0xa8 }, { 0x51, 0xcf }, { 0x50, 0xa9 }, { 0x51, 0xff }, - { 0x50, 0xaa }, { 0x51, 0xff }, - { 0x50, 0xab }, { 0x51, 0xff }, + { 0x50, 0xaa }, { 0x51, 0x0c }, + { 0x50, 0xab }, { 0x51, 0xcf }, { 0x50, 0xac }, { 0x51, 0xff }, - { 0x50, 0xad }, { 0x51, 0xff }, - { 0x50, 0xae }, { 0x51, 0xff }, + { 0x50, 0xad }, { 0x51, 0x0c }, + { 0x50, 0xae }, { 0x51, 0xcf }, { 0x50, 0xaf }, { 0x51, 0xff }, + { 0x5e, 0x07 }, { 0x50, 0xdc }, { 0x51, 0x01 }, { 0x50, 0xdd }, { 0x51, 0xf4 },
@@ -734,6 +754,14 @@ static int mb86a20s_get_ber_before_vterbi(struct dvb_frontend *fe,"%s: bit count before Viterbi for layer %c: %d.\n" , __func__, 'A' + layer, *count); +/* Reset counter to collect new data */ + rc =mb86a20s_writereg (state,0x53 ,0x07 & ~(1 << layer)); +if (rc <0 ) +return rc; + rc =mb86a20s_writereg (state,0x53 ,0x07 ); +if (rc <0 ) +return rc; +return 0 ; }
@@ -823,7 +851,11 @@ static int mb86a20s_get_stats(struct dvb_frontend *fe) } } -if (active_layers == ber_layers) { +/* +* Start showing global count if at least one error count is +* available. +*/ +if (ber_layers) {/* * All BER values are read. We can now calculate the total BER * And ask for another BER measure
@@ -836,12 +868,6 @@ static int mb86a20s_get_stats(struct dvb_frontend *fe) c->bit_count.stat[0 ].scale =FE_SCALE_COUNTER ; c->bit_count.stat[0 ].uvalue += t_bit_count; -/* Reset counters to collect new data */ - rc =mb86a20s_writeregdata (state, mb86a20s_vber_reset); -if (rc <0 ) -dev_err (&state->i2c->dev, -"%s: Can't reset VBER registers.\n" , __func__); -/* All BER measures need to be collected when ready */ for (i =0 ; i <3 ; i++) state->read_ber[i] = true;
Signature · 1 line
1.7.11.7
RFC PATCH v11 13/16 mb86a20s: improve bit error count for BER
In reply to Mauro Carvalho ChehabDo a better job on setting the bit error counters, in order to have all layer measures to happen in a little less than one second.
--- drivers/media/dvb-frontends/mb86a20s.c | 186 ++++++++++++++++++++++++++++----- 1 file changed, 162 insertions(+), 24 deletions(-)
drivers/media/dvb-frontends/mb86a20s.c +162 -24
@@ -30,6 +30,8 @@ struct mb86a20s_state {struct dvb_frontend frontend; +u32 estimated_rate[3 ]; +bool need_init;/*
@@ -89,31 +91,20 @@ static struct regdata mb86a20s_init[] = {/* * On this demod, when the bit count reaches the count below, -* it collects the bit error count. -* -* As FE thread runs on every 3 seconds, adjust the counters to -* provide one collect before 3 seconds, at the worse case (DQPSK, -* 1/4 guard interval, 1/2 FEC, 1-seg rate is 280 Mbps, and -* 3 seconds takes 0xcdb9f bits. Rounds it down to 0xccfff -* -* It should be noticed, however, that, with QAM-64 1/32 guard interval, -* 1 segment bit rate is 1.78 Mbps, and 12-seg is about 21.5 Mbps. -* At such rate, the time to measure BER is about 40 ms. -* -* It makes sense to change the logic there to use TMCC parameters and -* adjust the counters in order to have all of them to take a little -* less than 3 seconds, in order to have a more realistic BER rate, -* instead of having short samples for 12-segs. +* it collects the bit error count. The bit counters are initialized +* to 65535 here. This warrants that all of them will be quickly +* calculated when device gets locked. As TMCC is parsed, the values +* will be adjusted later in the driver's code. */ { 0x52, 0x01 }, /* Turn on BER before Viterbi */ - { 0x50, 0xa7 }, { 0x51, 0x0c }, - { 0x50, 0xa8 }, { 0x51, 0xcf }, + { 0x50, 0xa7 }, { 0x51, 0x00 }, + { 0x50, 0xa8 }, { 0x51, 0xff }, { 0x50, 0xa9 }, { 0x51, 0xff }, - { 0x50, 0xaa }, { 0x51, 0x0c }, - { 0x50, 0xab }, { 0x51, 0xcf }, + { 0x50, 0xaa }, { 0x51, 0x00 }, + { 0x50, 0xab }, { 0x51, 0xff }, { 0x50, 0xac }, { 0x51, 0xff }, - { 0x50, 0xad }, { 0x51, 0x0c }, - { 0x50, 0xae }, { 0x51, 0xcf }, + { 0x50, 0xad }, { 0x51, 0x00 }, + { 0x50, 0xae }, { 0x51, 0xff }, { 0x50, 0xaf }, { 0x51, 0xff }, { 0x5e, 0x07 },
@@ -208,7 +199,7 @@ static struct regdata mb86a20s_clear_stats[] = {*/ static int mb86a20s_i2c_writereg (struct mb86a20s_state *state, -u8 i2c_addr,int reg,int data) +u8 i2c_addr,u8 reg,u8 data) {u8 buf[] = { reg, data };struct i2c_msg msg = {
@@ -504,6 +495,112 @@ static void mb86a20s_reset_frontend_cache(struct dvb_frontend *fe) c->isdbt_sb_segment_count =0 ; } +/* +* Estimates the bit rate using the per-segment bit rate given by +* ABNT/NBR 15601 spec (table 4). +*/ +static u32 isdbt_rate[3 ][5 ][4 ] = { + {/* DQPSK/QPSK */ + {280850 ,312060 ,330420 ,340430 },/* 1/2 */ + {374470 ,416080 ,440560 ,453910 },/* 2/3 */ + {421280 ,468090 ,495630 ,510650 },/* 3/4 */ + {468090 ,520100 ,550700 ,567390 },/* 5/6 */ + {491500 ,546110 ,578230 ,595760 },/* 7/8 */ + }, {/* QAM16 */ + {561710 ,624130 ,660840 ,680870 },/* 1/2 */ + {748950 ,832170 ,881120 ,907820 },/* 2/3 */ + {842570 ,936190 ,991260 ,1021300 },/* 3/4 */ + {936190 ,1040210 ,1101400 ,1134780 },/* 5/6 */ + {983000 ,1092220 ,1156470 ,1191520 },/* 7/8 */ + }, {/* QAM64 */ + {842570 ,936190 ,991260 ,1021300 },/* 1/2 */ + {1123430 ,1248260 ,1321680 ,1361740 },/* 2/3 */ + {1263860 ,1404290 ,1486900 ,1531950 },/* 3/4 */ + {1404290 ,1560320 ,1652110 ,1702170 },/* 5/6 */ + {1474500 ,1638340 ,1734710 ,1787280 },/* 7/8 */ + } +}; + +static void mb86a20s_layer_bitrate (struct dvb_frontend *fe,u32 layer, +u32 modulation,u32 fec,u32 interleaving, +u32 segment) +{ +struct mb86a20s_state *state = fe->demodulator_priv; +u32 rate; +int m, f, i; + +/* +* default is always the lowest bit rate, to be sure that it will +* take less than 1 second to count the bits +*/ +switch (modulation) { +case DQPSK : +case QPSK : +default : + m =0 ; +break ; +case QAM_16 : + m =1 ; +break ; +case QAM_64 : + m =2 ; +break ; + } + +switch (fec) { +default : +case FEC_1_2 : +case FEC_AUTO : + f =0 ; +break ; +case FEC_2_3 : + f =1 ; +break ; +case FEC_3_4 : + f =2 ; +break ; +case FEC_5_6 : + f =3 ; +break ; +case FEC_7_8 : + f =4 ; +break ; + } + +switch (interleaving) { +default : +case GUARD_INTERVAL_1_4 : + i =0 ; +break ; +case GUARD_INTERVAL_1_8 : + i =1 ; +break ; +case GUARD_INTERVAL_1_16 : + i =2 ; +break ; +case GUARD_INTERVAL_1_32 : + i =3 ; +break ; + } + +/* +* Estimates a rate below the real one, to have more hope that the +* BER calculus will finish before 1 second. +*/ + rate = (isdbt_rate[m][f][i] >>16 ) <<15 ; + +/* Multiplies the rate by the number of segments */ + rate *= segment; + +dev_dbg (&state->i2c->dev, +"%s: layer %c bitrate: %d kbps; counter = %d (0x%06x)\n" , + __func__,'A' + layer, segment * isdbt_rate[m][f][i]/1000 , + rate, rate); + + state->estimated_rate[i] = rate; +} + +static int mb86a20s_get_frontend (struct dvb_frontend *fe) {struct mb86a20s_state *state = fe->demodulator_priv;
@@ -533,10 +630,11 @@ static int mb86a20s_get_frontend(struct dvb_frontend *fe) rc =mb86a20s_get_segment_count (state, i);if (rc <0 ) goto noperlayer_error; -if (rc >=0 && rc <14 ) +if (rc >=0 && rc <14 ) { c->layer[i].segment_count = rc; -else { + }else { c->layer[i].segment_count =0 ; + state->estimated_rate[i] =0 ;continue ; } c->isdbt_layer_enabled |=1 << i;
@@ -558,6 +656,10 @@ static int mb86a20s_get_frontend(struct dvb_frontend *fe)dev_dbg (&state->i2c->dev,"%s: interleaving %d.\n" , __func__, rc); c->layer[i].interleaving = rc; +mb86a20s_layer_bitrate (fe, i, c->layer[i].modulation, + c->layer[i].fec, + c->layer[i].interleaving, + c->layer[i].segment_count); } rc =mb86a20s_writereg (state,0x6d ,0x84 );
@@ -754,6 +856,42 @@ static int mb86a20s_get_ber_before_vterbi(struct dvb_frontend *fe,"%s: bit count before Viterbi for layer %c: %d.\n" , __func__, 'A' + layer, *count); +/* +* As we get TMCC data from the frontend, we can better estimate the +* BER bit counters, in order to do the BER measure during a longer +* time. Use those data, if available, to update the bit count +* measure. +*/ + +if (state->estimated_rate[layer] + && state->estimated_rate[layer] != *count) { +dev_dbg (&state->i2c->dev, +"%s: updating layer %c counter to %d.\n" , + __func__,'A' + layer, state->estimated_rate[layer]); + rc =mb86a20s_writereg (state,0x50 ,0xa7 + layer *3 ); +if (rc <0 ) +return rc; + rc =mb86a20s_writereg (state,0x51 , + state->estimated_rate[layer] >>16 ); +if (rc <0 ) +return rc; + rc =mb86a20s_writereg (state,0x50 ,0xa8 + layer *3 ); +if (rc <0 ) +return rc; + rc =mb86a20s_writereg (state,0x51 , + state->estimated_rate[layer] >>8 ); +if (rc <0 ) +return rc; + rc =mb86a20s_writereg (state,0x50 ,0xa9 + layer *3 ); +if (rc <0 ) +return rc; + rc =mb86a20s_writereg (state,0x51 , + state->estimated_rate[layer]); +if (rc <0 ) +return rc; + } + +/* Reset counter to collect new data */ rc =mb86a20s_writereg (state,0x53 ,0x07 & ~(1 << layer));if (rc <0 )
Signature · 1 line
1.7.11.7
RFC PATCH v11 14/16 dvb: increase API version
In reply to Mauro Carvalho ChehabDue to statistics, we should update the DVB API version.
--- Documentation/DocBook/media/dvb/dvbapi.xml | 2 +- include/uapi/linux/dvb/version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Documentation/DocBook/media/dvb/dvbapi.xml +1 -1
@@ -84,7 +84,7 @@ Added ISDB-T test originally written by Patrick Boettcher <title>LINUX DVB API</title> -<subtitle>Version 5.8</subtitle> +<subtitle>Version 5.10</subtitle> <!-- ADD THE CHAPTERS HERE --> <chapter id="dvb_introdution"> &sub-intro;
include/uapi/linux/dvb/version.h +1 -1
@@ -24,6 +24,6 @@#define _DVBVERSION_H_#define DVB_API_VERSION 5 -#define DVB_API_VERSION_MINOR 9 +#define DVB_API_VERSION_MINOR 10#endif /*_DVBVERSION_H_*/
Signature · 1 line
1.7.11.7
RFC PATCH v11 15/16 mb86a20s: global stat is just a sum, and not an increment
In reply to Mauro Carvalho ChehabAs global BER stat is already summing both BER counters, it should not be incremented with its previous value.
--- drivers/media/dvb-frontends/mb86a20s.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/dvb-frontends/mb86a20s.c +2 -2
@@ -1002,9 +1002,9 @@ static int mb86a20s_get_stats(struct dvb_frontend *fe)* bit errors on all active layers. */ c->bit_error.stat[0 ].scale =FE_SCALE_COUNTER ; - c->bit_error.stat[0 ].uvalue += t_bit_error; + c->bit_error.stat[0 ].uvalue = t_bit_error; c->bit_count.stat[0 ].scale =FE_SCALE_COUNTER ; - c->bit_count.stat[0 ].uvalue += t_bit_count; + c->bit_count.stat[0 ].uvalue = t_bit_count;/* All BER measures need to be collected when ready */ for (i =0 ; i <3 ; i++)
Signature · 1 line
1.7.11.7
RFC PATCH v11 16/16 mb86a20s: Add CNR measurement
In reply to Mauro Carvalho Chehab--- drivers/media/dvb-frontends/mb86a20s.c | 328 ++++++++++++++++++++++++++++++++- 1 file changed, 326 insertions(+), 2 deletions(-)
v2: Several fixes and cleanups for the per-layer CNR measures.
drivers/media/dvb-frontends/mb86a20s.c +326 -2
@@ -121,10 +121,14 @@ static struct regdata mb86a20s_init[] = { { 0x50, 0xb5 }, { 0x51, 0xff }, { 0x50, 0xb6 }, { 0x51, 0xff }, { 0x50, 0xb7 }, { 0x51, 0xff }, - { 0x50, 0x50 }, { 0x51, 0x02 }, + + { 0x50, 0x50 }, { 0x51, 0x02 }, /* MER manual mode */ { 0x50, 0x51 }, { 0x51, 0x04 }, /* MER symbol 4 */ + { 0x50, 0x50 }, { 0x51, 0x03 }, /* MER manual mode + RST */ + { 0x50, 0x50 }, { 0x51, 0x02 }, /* MER manual mode */ { 0x45, 0x04 }, /* CN symbol 4 */ - { 0x48, 0x04 }, + { 0x48, 0x04 }, /* CN manual mode */ + { 0x50, 0xd5 }, { 0x51, 0x01 }, /* Serial */ { 0x50, 0xd6 }, { 0x51, 0x1f }, { 0x50, 0xd2 }, { 0x51, 0x03 },
@@ -897,6 +901,322 @@ static int mb86a20s_get_ber_before_vterbi(struct dvb_frontend *fe,if (rc <0 )return rc; rc =mb86a20s_writereg (state,0x53 ,0x07 ); + +return 0 ; +} + +struct linear_segments { +unsigned x, y; +}; + +/* +* All tables below return a dB/1000 measurement +*/ + +static struct linear_segments cnr_to_db_table[] = { + {19648 ,0 }, + {18187 ,1000 }, + {16534 ,2000 }, + {14823 ,3000 }, + {13161 ,4000 }, + {11622 ,5000 }, + {10279 ,6000 }, + {9089 ,7000 }, + {8042 ,8000 }, + {7137 ,9000 }, + {6342 ,10000 }, + {5641 ,11000 }, + {5030 ,12000 }, + {4474 ,13000 }, + {3988 ,14000 }, + {3556 ,15000 }, + {3180 ,16000 }, + {2841 ,17000 }, + {2541 ,18000 }, + {2276 ,19000 }, + {2038 ,20000 }, + {1800 ,21000 }, + {1625 ,22000 }, + {1462 ,23000 }, + {1324 ,24000 }, + {1175 ,25000 }, + {1063 ,26000 }, + {980 ,27000 }, + {907 ,28000 }, + {840 ,29000 }, + {788 ,30000 }, +}; + +static struct linear_segments cnr_64qam_table[] = { + {3922688 ,0 }, + {3920384 ,1000 }, + {3902720 ,2000 }, + {3894784 ,3000 }, + {3882496 ,4000 }, + {3872768 ,5000 }, + {3858944 ,6000 }, + {3851520 ,7000 }, + {3838976 ,8000 }, + {3829248 ,9000 }, + {3818240 ,10000 }, + {3806976 ,11000 }, + {3791872 ,12000 }, + {3767040 ,13000 }, + {3720960 ,14000 }, + {3637504 ,15000 }, + {3498496 ,16000 }, + {3296000 ,17000 }, + {3031040 ,18000 }, + {2715392 ,19000 }, + {2362624 ,20000 }, + {1963264 ,21000 }, + {1649664 ,22000 }, + {1366784 ,23000 }, + {1120768 ,24000 }, + {890880 ,25000 }, + {723456 ,26000 }, + {612096 ,27000 }, + {518912 ,28000 }, + {448256 ,29000 }, + {388864 ,30000 }, +}; + +static struct linear_segments cnr_16qam_table[] = { + {5314816 ,0 }, + {5219072 ,1000 }, + {5118720 ,2000 }, + {4998912 ,3000 }, + {4875520 ,4000 }, + {4736000 ,5000 }, + {4604160 ,6000 }, + {4458752 ,7000 }, + {4300288 ,8000 }, + {4092928 ,9000 }, + {3836160 ,10000 }, + {3521024 ,11000 }, + {3155968 ,12000 }, + {2756864 ,13000 }, + {2347008 ,14000 }, + {1955072 ,15000 }, + {1593600 ,16000 }, + {1297920 ,17000 }, + {1043968 ,18000 }, + {839680 ,19000 }, + {672256 ,20000 }, + {523008 ,21000 }, + {424704 ,22000 }, + {345088 ,23000 }, + {280064 ,24000 }, + {221440 ,25000 }, + {179712 ,26000 }, + {151040 ,27000 }, + {128512 ,28000 }, + {110080 ,29000 }, + {95744 ,30000 }, +}; + +struct linear_segments cnr_qpsk_table[] = { + {2834176 ,0 }, + {2683648 ,1000 }, + {2536960 ,2000 }, + {2391808 ,3000 }, + {2133248 ,4000 }, + {1906176 ,5000 }, + {1666560 ,6000 }, + {1422080 ,7000 }, + {1189632 ,8000 }, + {976384 ,9000 }, + {790272 ,10000 }, + {633344 ,11000 }, + {505600 ,12000 }, + {402944 ,13000 }, + {320768 ,14000 }, + {255488 ,15000 }, + {204032 ,16000 }, + {163072 ,17000 }, + {130304 ,18000 }, + {105216 ,19000 }, + {83456 ,20000 }, + {65024 ,21000 }, + {52480 ,22000 }, + {42752 ,23000 }, + {34560 ,24000 }, + {27136 ,25000 }, + {22016 ,26000 }, + {18432 ,27000 }, + {15616 ,28000 }, + {13312 ,29000 }, + {11520 ,30000 }, +}; + +static s64 interpolate_value (u32 value,struct linear_segments *segments, +unsigned len) +{ +struct linear_segments *seg; +s64 tmp64; +int i, dx, dy; + +if (value >= segments[0 ].x) +return segments[0 ].y; +if (value < segments[len-1 ].x) +return segments[len-1 ].y; + +for (i =1 ; i < len -1 ; i++) +if (value >= segments[i].x) +break ; + seg = &segments[i]; + +/* Linear interpolation between the two (x,y) points */ + dy = segments[i].y - segments[i -1 ].y; + dx = segments[i -1 ].x - segments[i].x; + tmp64 = dy * ((u64 )value - seg->x - (dx >>1 )); +do_div (tmp64, dx); +return seg->y - tmp64; +} + +static int mb86a20s_get_main_CNR (struct dvb_frontend *fe) +{ +struct mb86a20s_state *state = fe->demodulator_priv; +struct dtv_frontend_properties *c = &fe->dtv_property_cache; +u32 cnr_linear, cnr; +int rc, val; + +/* Check if CNR is available */ + rc =mb86a20s_readreg (state,0x45 ); +if (rc <0 ) +return rc; + +if (!(rc &0x40 )) { +dev_info (&state->i2c->dev,"%s: CNR is not available yet.\n" , + __func__); +return -EBUSY ; + } + val = rc; + + rc =mb86a20s_readreg (state,0x46 ); +if (rc <0 ) +return rc; + cnr_linear = rc <<8 ; + + rc =mb86a20s_readreg (state,0x46 ); +if (rc <0 ) +return rc; + cnr_linear |= rc; + + cnr =interpolate_value (cnr_linear, + cnr_to_db_table,ARRAY_SIZE (cnr_to_db_table)); + + c->cnr.stat[0 ].scale =FE_SCALE_DECIBEL ; + c->cnr.stat[0 ].svalue = cnr; + +dev_dbg (&state->i2c->dev,"%s: CNR is %d.%03d dB (%d)\n" , + __func__, cnr /1000 , cnr %1000 , cnr_linear); + +/* CNR counter reset */ + rc =mb86a20s_writereg (state,0x45 , val |0x10 ); +if (rc <0 ) +return rc; + rc =mb86a20s_writereg (state,0x45 , val &0x6f ); + +return rc; +} + +static int mb86a20s_get_per_layer_CNR (struct dvb_frontend *fe) +{ +struct mb86a20s_state *state = fe->demodulator_priv; +struct dtv_frontend_properties *c = &fe->dtv_property_cache; +u32 mer, cnr; +int rc, val, i; +struct linear_segments *segs; +unsigned segs_len; + +dev_dbg (&state->i2c->dev,"%s called.\n" , __func__); + +/* Check if the measures are already available */ + rc =mb86a20s_writereg (state,0x50 ,0x5b ); +if (rc <0 ) +return rc; + rc =mb86a20s_readreg (state,0x51 ); +if (rc <0 ) +return rc; + +/* Check if data is available */ +if (!(rc &0x01 )) { +dev_info (&state->i2c->dev, +"%s: MER measures aren't available yet.\n" , __func__); +return -EBUSY ; + } + +/* Read all layers */ +for (i =0 ; i <3 ; i++) { +if (!(c->isdbt_layer_enabled & (1 << i))) { + c->cnr.stat[1 + i].scale =FE_SCALE_NOT_AVAILABLE ; +continue ; + } + + rc =mb86a20s_writereg (state,0x50 ,0x52 + i *3 ); +if (rc <0 ) +return rc; + rc =mb86a20s_readreg (state,0x51 ); +if (rc <0 ) +return rc; + mer = rc <<16 ; + rc =mb86a20s_writereg (state,0x50 ,0x53 + i *3 ); +if (rc <0 ) +return rc; + rc =mb86a20s_readreg (state,0x51 ); +if (rc <0 ) +return rc; + mer |= rc <<8 ; + rc =mb86a20s_writereg (state,0x50 ,0x54 + i *3 ); +if (rc <0 ) +return rc; + rc =mb86a20s_readreg (state,0x51 ); +if (rc <0 ) +return rc; + mer |= rc; + +switch (c->layer[i].modulation) { +case DQPSK : +case QPSK : + segs = cnr_qpsk_table; + segs_len =ARRAY_SIZE (cnr_qpsk_table); +break ; +case QAM_16 : + segs = cnr_16qam_table; + segs_len =ARRAY_SIZE (cnr_16qam_table); +break ; +default : +case QAM_64 : + segs = cnr_64qam_table; + segs_len =ARRAY_SIZE (cnr_64qam_table); +break ; + } + cnr =interpolate_value (mer, segs, segs_len); + + c->cnr.stat[1 + i].scale =FE_SCALE_DECIBEL ; + c->cnr.stat[1 + i].svalue = cnr; + +dev_dbg (&state->i2c->dev, +"%s: CNR for layer %c is %d.%03d dB (MER = %d).\n" , + __func__,'A' + i, cnr /1000 , cnr %1000 , mer); + + } + +/* Start a new MER measurement */ +/* MER counter reset */ + rc =mb86a20s_writereg (state,0x50 ,0x50 ); +if (rc <0 ) +return rc; + rc =mb86a20s_readreg (state,0x51 ); +if (rc <0 ) +return rc; + val = rc; + + rc =mb86a20s_writereg (state,0x51 , val |0x01 ); +if (rc <0 ) +return rc; + rc =mb86a20s_writereg (state,0x51 , val &0x06 );if (rc <0 )return rc;
@@ -948,7 +1268,11 @@ static int mb86a20s_get_stats(struct dvb_frontend *fe)dev_dbg (&state->i2c->dev,"%s called.\n" , __func__); +mb86a20s_get_main_CNR (fe); +/* Get per-layer stats */ +mb86a20s_get_per_layer_CNR (fe); +for (i =0 ; i <3 ; i++) {if (c->isdbt_layer_enabled & (1 << i)) {/* Layer is active and has rc segments */
Signature · 1 line
1.7.11.7