History log of /linux-master/drivers/media/dvb-frontends/dib8000.c
Revision Date Author Comments
# 86495af1 08-Sep-2023 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

media: dvb: symbol fixup for dvb_attach()

In commit 9011e49d54dc ("modules: only allow symbol_get of
EXPORT_SYMBOL_GPL modules") the use of symbol_get is properly restricted
to GPL-only marked symbols. This interacts oddly with the DVB logic
which only uses dvb_attach() to load the dvb driver which then uses
symbol_get().

Fix this up by properly marking all of the dvb_attach attach symbols as
EXPORT_SYMBOL_GPL().

Fixes: 9011e49d54dc ("modules: only allow symbol_get of EXPORT_SYMBOL_GPL modules")
Cc: stable <stable@kernel.org>
Reported-by: Stefan Lippers-Hollmann <s.l-h@gmx.de>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: linux-media@vger.kernel.org
Cc: linux-modules@vger.kernel.org
Acked-by: Luis Chamberlain <mcgrof@kernel.org>
Acked-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Link: https://lore.kernel.org/r/20230908092035.3815268-2-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# f97fa3dc 03-Jul-2023 Andy Shevchenko <andriy.shevchenko@linux.intel.com>

lib/math: Move dvb_math.c into lib/math/int_log.c

Some existing and new users may benefit from the intlog2() and
intlog10() APIs, make them wide available.

Reviewed-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Acked-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Link: https://lore.kernel.org/r/20230619172019.21457-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Randy Dunlap <rdunlap@infradead.org>
Link: https://lore.kernel.org/r/20230703135211.87416-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# d063ddfb 14-Jul-2022 Jason Wang <wangborong@cdjrlc.com>

media: dib8000: Fix comment typo

The double `this' is duplicated in line 3215, remove one.

[hverkuil: while we're at it, fix the 'succedeed' typo as well]

Signed-off-by: Jason Wang <wangborong@cdjrlc.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>


# 8dbdcc72 30-Nov-2021 Zhou Qingyang <zhou1615@umn.edu>

media: dib8000: Fix a memleak in dib8000_init()

In dib8000_init(), the variable fe is not freed or passed out on the
failure of dib8000_identify(&state->i2c), which could lead to a memleak.

Fix this bug by adding a kfree of fe in the error path.

This bug was found by a static analyzer. The analysis employs
differential checking to identify inconsistent security operations
(e.g., checks or kfrees) between two code paths and confirms that the
inconsistent operations are not recovered in the current function or
the callers, so they constitute bugs.

Note that, as a bug found by static analysis, it can be a false
positive or hard to trigger. Multiple researchers have cross-reviewed
the bug.

Builds with CONFIG_DVB_DIB8000=m show no new warnings,
and our static analyzer no longer warns about this code.

Fixes: 77e2c0f5d471 ("V4L/DVB (12900): DiB8000: added support for DiBcom ISDB-T/ISDB-Tsb demodulator DiB8000")
Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>


# 8db11aeb 17-Jun-2021 Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

media: dib8000: rewrite the init prbs logic

The logic at dib8000_get_init_prbs() has a few issues:

1. the tables used there has an extra unused value at the beginning;
2. the dprintk() message doesn't write the right value when
transmission mode is not 8K;
3. the array overflow validation is done by the callers.

Rewrite the code to fix such issues.

This should also shut up those smatch warnings:

drivers/media/dvb-frontends/dib8000.c:2125 dib8000_get_init_prbs() error: buffer overflow 'lut_prbs_8k' 14 <= 14
drivers/media/dvb-frontends/dib8000.c:2129 dib8000_get_init_prbs() error: buffer overflow 'lut_prbs_2k' 14 <= 14
drivers/media/dvb-frontends/dib8000.c:2131 dib8000_get_init_prbs() error: buffer overflow 'lut_prbs_4k' 14 <= 14
drivers/media/dvb-frontends/dib8000.c:2134 dib8000_get_init_prbs() error: buffer overflow 'lut_prbs_8k' 14 <= 14

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>


# a10e763b 31-May-2019 Thomas Gleixner <tglx@linutronix.de>

treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 372

Based on 1 normalized pattern(s):

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

extracted by the scancode license scanner the SPDX license identifier

GPL-2.0-only

has been chosen to replace the boilerplate/reference in 135 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Allison Randal <allison@lohutok.net>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190531081036.435762997@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 85709cbf 10-Sep-2018 Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

media: replace strncpy() by strscpy()

The strncpy() function is being deprecated upstream. Replace
it by the safer strscpy().

While here, replace a few occurences of strlcpy() that were
recently added to also use strscpy().

Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>


# 868c9a17 18-Feb-2019 Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

media: dvb-frontends: fix several typos

Use codespell to fix lots of typos over frontends.

Manually verified to avoid false-positives.

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>


# f1b1eabf 05-Jul-2018 Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

media: dvb: represent min/max/step/tolerance freqs in Hz

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 <suzuki.katsuhiro@socionext.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>


# 6396bb22 12-Jun-2018 Kees Cook <keescook@chromium.org>

treewide: kzalloc() -> kcalloc()

The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:

kzalloc(a * b, gfp)

with:
kcalloc(a * b, gfp)

as well as handling cases of:

kzalloc(a * b * c, gfp)

with:

kzalloc(array3_size(a, b, c), gfp)

as it's slightly less ugly than:

kzalloc_array(array_size(a, b), c, gfp)

This does, however, attempt to ignore constant size factors like:

kzalloc(4 * 1024, gfp)

though any constants defined via macros get caught up in the conversion.

Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.

The Coccinelle script used for this was:

// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@

(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)

// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@

(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)

// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@

(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)

// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@

- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)

// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@

(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)

// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@

(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)

// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@

(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)

// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@

(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)

// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@

(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)

Signed-off-by: Kees Cook <keescook@chromium.org>


# 7aa92c42 25-Dec-2017 Dan Gopstein <dgopstein@nyu.edu>

media: ABS macro parameter parenthesization

Replace usages of the locally defined ABS() macro with calls to the
canonical abs() from kernel.h and remove the old definitions of ABS()

This change was originally motivated by two local definitions of the
ABS (absolute value) macro that fail to parenthesize their parameter
properly. This can lead to a bad expansion for low-precedence
expression arguments.

For example: ABS(1-2) currently expands to ((1-2) < 0 ? (-1-2) : (1-2))
which evaluates to -3. But the correct expansion would be
((1-2) < 0 ? -(1-2) : (1-2)) which evaluates to 1.

Signed-off-by: Dan Gopstein <dgopstein@nyu.edu>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# fada1935 28-Dec-2017 Mauro Carvalho Chehab <mchehab@kernel.org>

media: move dvb kAPI headers to include/media

Except for DVB, all media kAPI headers are at include/media.

Move the headers to it.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# 47bdf7c6 26-Aug-2017 Dan Carpenter <dan.carpenter@oracle.com>

media: dib8000: remove some bogus dead code

This function is broken. It sets the wrong front_end to NULL. But it's
not used, so let's just delete it.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# 28e83542 09-Jul-2017 Gustavo A. R. Silva <garsilva@embeddedor.com>

media: dib8000: constify i2c_algorithm structure

Check for i2c_algorithm structures that are only stored in
the algo field of an i2c_adapter structure. This field is
declared const, so i2c_algorithm structures that have this
property can be declared as const also.

This issue was identified using Coccinelle and the following
semantic patch:

@r disable optional_qualifier@
identifier i;
position p;
@@
static struct i2c_algorithm i@p = { ... };

@ok@
identifier r.i;
struct i2c_adapter e;
position p;
@@
e.algo = &i@p;

@bad@
position p != {r.p,ok.p};
identifier r.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r.i;
@@
static
+const
struct i2c_algorithm i = { ... };

Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# 8af16adf 14-Oct-2016 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: use pr_foo() instead of printk()

The dprintk() macro relies on continuation lines. This is not
a good practice and will break after commit 563873318d32
("Merge branch 'printk-cleanups'").

So, instead of directly calling printk(), use pr_foo() macros,
adding a\n leading char on each macro call.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>


# 7e3e68bc 03-Feb-2016 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dvb_frontend: pass the props cache to get_frontend() as arg

Instead of using the DTV properties cache directly, pass the get
frontend data as an argument. For now, everything should remain
the same, but the next patch will prevent get_frontend to
affect the global cache.

This is needed because several drivers don't care enough to only
change the properties if locked. Due to that, calling
G_PROPERTY before locking on those drivers will make them to
never lock. Ok, those drivers are crap and should never be
merged like that, but the core should not rely that the drivers
would be doing the right thing.

Reviewed-by: Michael Ira Krufky <mkrufky@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 99e44da7 23-Jan-2016 Patrick Boettcher <patrick.boettcher@posteo.de>

[media] media: change email address

Soon my dibcom.fr/parrot.com-address won't respond anymore.
Thus I'm replacing it. And, while being at it,
let's adapt some other (old) email-addresses as well.

Signed-off-by: Patrick Boettcher <patrick.boettcher@posteo.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 0df289a2 07-Jun-2015 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dvb: Get rid of typedev usage for enums

The DVB API was originally defined using typedefs. This is against
Kernel CodingStyle, and there's no good usage here. While we can't
remove its usage on userspace, we can avoid its usage in Kernelspace.

So, let's do it.

This patch was generated by this shell script:

for j in $(grep typedef include/uapi/linux/dvb/frontend.h |cut -d' ' -f 3); do for i in $(find drivers/media -name '*.[ch]' -type f) $(find drivers/staging/media -name '*.[ch]' -type f); do sed "s,${j}_t,enum $j," <$i >a && mv a $i; done; done

While here, make CodingStyle fixes on the affected lines.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Stefan Richter <stefanr@s5r6.in-berlin.de> # for drivers/media/firewire/*


# 901c4ad6 23-Dec-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: upd_demod_gain_period should be u32

X-Patchwork-Delegate: m.chehab@samsung.com
As shown at the code, upd_demod_gain_period is used to write
to two 16-bit registers:
dib8000_write_word(state, 1946, upd_demod_gain_period & 0xFFFF);
dib8000_write_word(state, 1947, reg | (1<<14) | ((upd_demod_gain_period >> 16) & 0xFF));

So, it should be declared as u32.

This fixes the following smatch warning:
drivers/media/dvb-frontends/dib8000.c:1282 dib8000_agc_startup() warn: right shifting more than type allows

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>


# 3c0d394e 04-Jul-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: improve the message that reports per-layer locks

The message is currently highly encoded:
[70299.863521] DiB8000: Mpeg locks [ L0 : 0 | L1 : 1 | L2 : 0 ]

And doesn't properly reflect that some problems might have happened.
Instead, display it as:
[75160.822321] DiB8000: Not all ISDB-T layers locked in 32 ms: Layer A NOT LOCKED, Layer B locked, Layer C not enabled

In order to better reflect what's happening with layer locking.

Acked-By: Patrick Boettcher <pboettcher@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# ecc31d55 04-Jul-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: improve debug messages

When debug is enabled:
- Report when frontend gets restarted;
- Be coherent on the displayed lines;
- Show the transmission mode;
- Hide unused layers.

No functional changes (except at the printk's).

Acked-By: Patrick Boettcher <pboettcher@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# a768f90e 04-Jul-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: Update the ADC gain table

This table doesn't match the new one.
Update it.

Acked-By: Patrick Boettcher <pboettcher@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# d6c62b76 04-Jul-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: use jifies instead of current_kernel_time()

Instead of doing the tuning delays and timeouts using
current_kernel_time(), use jiffies. That consumes less
CPU cycles, and it is monotonic.

Acked-By: Patrick Boettcher <pboettcher@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 4607bb7a 04-Jul-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: Fix the sleep time at the state machine

msleep() is not too precise: its precision depends on the
HZ config. As the driver selects precise timings for the
state machine, change it to usleep_range().

Acked-By: Patrick Boettcher <pboettcher@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 6d38454a 04-Jul-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: Restart sad during dib8000_reset

Just like the Windows driver, restart SAD during reset

Acked-By: Patrick Boettcher <pboettcher@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# dde8e115 04-Jul-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: In auto-search, try first with partial reception enabled

TV broadcasters generally use partial reception. So, enable it by
default in auto-search mode. The driver will latter detect if the
transmission is on some other mode.

Acked-By: Patrick Boettcher <pboettcher@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 08623517 04-Jul-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: remove a double call for dib8000_get_symbol_duration()

The symbol duration was already obtained at CT_DEMOD_START.
No need to do it again at CT_DEMOD_STEP_3.

Acked-By: Patrick Boettcher <pboettcher@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 7fec1c80 04-Jul-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: Fix: add missing 4K FFT mode

Without that, tuning may fail on 4K FFT mode, as the transmission
parameter cache will be initialized with a wrong value.

Acked-By: Patrick Boettcher <pboettcher@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 7fa676c6 04-Jul-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: Fix alignments at dib8000_tune()

There are two tabs instead of one aligning this struct.
Worse than that, on some places, the alignment is wrong.
Fix it.

No functional changes.

Acked-By: Patrick Boettcher <pboettcher@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# c063c7c6 04-Jul-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: Fix ADC OFF settings

The ADC OFF values are wrong. This causes troubles on detecting
weak signals.

Acked-By: Patrick Boettcher <pboettcher@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 34ba2e65 04-Jul-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: Fix handling of interleave bigger than 2

If interleave is bigger than 2, the code will set it to 0, as
dib8000 registers use a log2(). So, change the code to handle
it accordingly.

Acked-By: Patrick Boettcher <pboettcher@kernellabs.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# d44913c1 29-May-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: export just one symbol

Exporting multiple symbols don't work as it causes compilation
breakages, due to the way dvb_attach() works.

The bug happens when:
CONFIG_DVB_DIB8000=m
CONFIG_DVB_USB_DIB0700=y

As a bonus, dib8000 won't be loaded anymore if the device uses
a different frontend, reducing the memory footprint.

Tested with both Pixelview PV-D231 and MyGica S870.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# b9bc7d59 29-May-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: rename dib8000_attach to dib8000_init

Well, what we call as "foo_attach" is the method that should
be called by the dvb_attach() macro.

It should be noticed that the name "dvb_attach" is really a
bad name and don't express what it does.

dvb_attach() basically does three things, if the frontend is
compiled as a module:
- It lookups for the module that it is known to have the
given symbol name and requests such module;
- It increments the module usage (anonymously - so lsmod
doesn't print who loaded the module);
- after loading the module, it runs the function associated
with the dynamic symbol.

When compiled as builtin, it just calls the function given to it.

As dvb_attach() increments refcount, it can't be (easily)
called more than once for the same module, or the kernel
will deny to remove the module, because refcount will never
be zeroed.

In other words, the function name given to dvb_attach()
should be one single symbol that will always be called
before any other function on that module to be used.

For almost all DVB frontends, there's just one function,
but, on dib8000, there are several exported symbols.

We need to get rid of all those direct calls, because they
cause compilation breakages when bridge is builtin and
frontend is module, we'll need to add a new function that
will be the first one to be called, whatever initialization
is needed.

So, let's rename this function, in order to prepare for
a next patch that will add a new attach() function that
will be the only one exported by this module.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# e4a3bc1c 13-Jan-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: Fix a few warnings when compiled for avr32

drivers/media/dvb-frontends/dib8000.c: In function 'dib8000_get_time_us':
drivers/media/dvb-frontends/dib8000.c:3957: warning: 'interleaving' may be used uninitialized in this function
drivers/media/dvb-frontends/dib8000.c:3956: warning: 'rate_denum' may be used uninitialized in this function

Those are actually false positives, but it doesn't hurt cleaning them.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 5dc8526b 13-Jan-2014 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: Properly represent long long integers

When compiling with avr32, it gets those errors:

drivers/media/dvb-frontends/dib8000.c: In function 'dib8000_get_stats':
drivers/media/dvb-frontends/dib8000.c:4121: warning: integer constant is too large for 'long' type

Fix integer representation to avoid overflow.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 4bf48150 20-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: fix compilation error

As reported by kbuild test robot <fengguang.wu@intel.com>:

with a random config:

drivers/built-in.o: In function `dib8000_get_time_us.isra.16':
>> dib8000.c:(.text+0x3075aa): undefined reference to `__udivdi3'

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 0400c535 17-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: improve block statistics

PER/UCB statistics are collected once on each 1 second.
However, it doesn't provide the total number of packets
needed to calculate PER.

Yet, as we know the bit rate, it is possible to estimate
such number. So, do it.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Acked-by: Patrick Boettcher <pboettcher@kernellabs.com>


# 704f01bb 17-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: be sure that stats are available before reading them

On dib8000, the BER statistics are updated on every 1.25e6 bits.
Adjust the code to only update the statistics after having it
done.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Acked-by: Patrick Boettcher <pboettcher@kernellabs.com>


# 7a9d85d5 17-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: Fix UCB measure with DVBv5 stats

On dib8000, the block error count is a monotonic 32 bits register.
With DVBv5 stats, we use a 64 bits counter, that it is reset
when a new channel is tuned.

Change the UCB counting start from 0 and to be returned with
64 bits, just like the API requests.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Acked-by: Patrick Boettcher <pboettcher@kernellabs.com>


# 42ff76bd 16-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: make a better estimation for dBm

Use multiple linear segments to better interpolate the dBm
for the signal strength.

The table that converts from linear strength to dB was
empirically determinated with the help of a signal generator
(DTA-2111).

The entries from -35dBm to -22.5dBm were taken using just
the signal generator and the board.

For the entries from -36dBm to -51dBm, a 16 dB tap was used,
in order to extend its range.

Signals below to -51dBm are just linearly interpolated.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Acked-by: Patrick Boettcher <pboettcher@kernellabs.com>


# b4600d70 16-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: estimate strength in dBm

Better to have Signal strength in dB.
This takes a very rough estimation for the signal strength,
that was calibrated using a Dektec DTA-2111 Gold RF generator
and a Pixelview dib8076 stick.

It estimates the signal strength using a linear equation where:
- the max is -22.5 dBm, with returns 55953
- the min is -35.0 dBm, with returns 50110

With -22dBm, the signal strengh is returned as 65535.
Unfortunately, the min strength generated with DTA-2111 is
-35dBm.

It should be noticed that approximating it by a linear equation
is not right. I should probably be splitting it into 0.5 dB
linear segments, in order to get a higher precision, just like
it is done on mb86a20s, but that would force me to add some
attenuators, in order to get dB levels below -35dBm, which is,
btw, strong enough to get signal lock.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Acked-by: Patrick Boettcher <pboettcher@kernellabs.com>


# 6ef06e78 16-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: add DVBv5 stats

The advantage of DVBv5 stats is that it allows adding proper
scales to all measures. use it for this frontend.

This patch adds a basic set of stats, basically cloning what's already
provided by DVBv3 API. Latter patches will improve it.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Acked-by: Patrick Boettcher <pboettcher@kernellabs.com>


# 51fea113 16-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: report Interleaving 4 correctly

On ISDB-T, the valid values for interleaving are 0, 1, 2 and 4.
While the first 3 are properly reported, the last one is reported
as 3 instead. Fix it.

Tested with a Dektec DTA-2111 RF generator.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Acked-by: Patrick Boettcher <pboettcher@kernellabs.com>


# ad976187 15-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: improves the auto search mode check logic

The logic that detects if auto search mode should be used is too
complex.

Also, it doesn't cover all cases, as the dib8000_tune logic
requires either auto mode or a fully specified manual mode.
So, move it to a separate function and add some extra debug
data to help identifying when it falled back to auto mode,
because the manual settings are invalid.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Acked-by: Patrick Boettcher <pboettcher@kernellabs.com>


# 70315b3e 15-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: Don't let tuner hang due to a call to get_frontend()

Both dvbv5-scan and dvbv5-zap tools call FE_GET_PROPERTY inside the
loop that checks for stats. If the frontend doesn't support DVBv5, it
falls back to call the DVBv5 stats APIs(FE_READ_BER, FE_READ_SIGNAL,
FE_READ_SNR and FE_READ_UNCORRECTED_BLOCKS).

A call to FE_GET_PROPERTY makes dvb-frontend core to call get_frontend().

However, due to a race condition on dib8000 between dib8000_get_frontend
and dib8000_tune, if get_frontend occurs too early, it causes the
tune state machine to fail and not get any lock.

This patch adds a workaround code that makes get_frontend() to just
return if none of the frontends have a SYNC. This change fixed the issue
with dvbv5-scan/dvbv5-zap, but a fine-tuned logic might be needed in
the future, when we implement DVBv5 stats on this frontend.

The procedure to test the bug and the fix is the one below:

1) tune into a non-existing frequency with:

$ dvbv5-zap -I dvbv5 -c non_existing_freqs -m 679142857 -t3

2) tune/lock into an existing frequency with:

$ dvbv5-zap -I dvbv5 -c isdb-test -m 479142857
or
$ dvbv5-scan isdb-test

In this case, 679 MHz carrier doesn't exist. Only 479 MHz does.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Acked-by: Patrick Boettcher <pboettcher@kernellabs.com>


# 5ac64ba1 13-Dec-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: make 32 bits read atomic

As the dvb-frontend kthread can be called anytime, it can race
with some get status ioctl. So, it seems better to avoid one to
race with the other while reading a 32 bits register.
I can't see any other reason for having a mutex there at I2C, except
to provide such kind of protection, as the I2C core already has a
mutex to protect I2C transfers.

Note: instead of this approach, it could eventually remove the dib8000
specific mutex for it, and either group the 4 ops into one xfer or
to manually control the I2C mutex. The main advantage of the current
approach is that the changes are smaller and more puntual.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Cc: stable@vger.kernel.org
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Acked-by: Patrick Boettcher <pboettcher@kernellabs.com>


# d67350f8 12-Dec-2013 Olivier Grenie <olivier.grenie@parrot.com>

[media] dib8000: fix regression with dib807x

Commit 173a64cb3fcf broke support for some dib807x versions.

Fix it by providing backward compatibility with the older versions.

[mkrufky@linuxtv.org: conflict handling and CodingStyle fixes]

Signed-off-by: Olivier Grenie <olivier.grenie@parrot.com>
Acked-by: Patrick Boettcher <pboettcher@kernellabs.com>
Cc: stable@vger.kernel.org
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# f58c91ce 20-Oct-2013 Jonathan McCrohan <jmccrohan@gmail.com>

[media] media_tree: Fix spelling errors

Fix various spelling errors in strings and comments throughout the media
tree. The majority of these were found using Lucas De Marchi's codespell
tool.

[m.chehab@samsung.com: discard hunks with conflicts]

Signed-off-by: Jonathan McCrohan <jmccrohan@gmail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 39c1cb2b 20-Oct-2013 Jonathan McCrohan <jmccrohan@gmail.com>

[media] media_tree: Fix spelling errors

Fix various spelling errors in strings and comments throughout the media
tree. The majority of these were found using Lucas De Marchi's codespell
tool.

[m.chehab@samsung.com: discard hunks with conflicts]

Signed-off-by: Jonathan McCrohan <jmccrohan@gmail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>


# 4d8d5d92 02-Jun-2013 Geert Uytterhoeven <geert@linux-m68k.org>

[media] dib8000: Fix dib8000_set_frontend() never setting ret

drivers/media/dvb-frontends/dib8000.c: In function ‘dib8000_set_frontend’:
drivers/media/dvb-frontends/dib8000.c:3556: warning: ‘ret’ is used uninitialized in this function
Remove the variable and return zero instead.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 13122f98 25-Apr-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: fix a warning

drivers/media/dvb-frontends/dib8000.c: In function 'dib8000_wait_lock':
drivers/media/dvb-frontends/dib8000.c:3972:1: warning: 'value' may be used uninitialized in this function [-Wmaybe-uninitialized]
drivers/media/dvb-frontends/dib8000.c:2419:6: note: 'value' was declared here

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 746f7ae0 25-Apr-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: Fix sub-channel range

isdbt_sb_subchannel is unsigned with 8 bits. So, it will
never be -1. Instead, any value bigger than 13 is invalid.

As is, the current code generates the following warnings:

drivers/media/dvb-frontends/dib8000.c: In function 'dib8000_set_isdbt_common_channel':
drivers/media/dvb-frontends/dib8000.c:2358:3: warning: comparison is always true due to limited range of data type [-Wtype-limits]
drivers/media/dvb-frontends/dib8000.c: In function 'dib8000_tune':
drivers/media/dvb-frontends/dib8000.c:3107:8: warning: comparison is always false due to limited range of data type [-Wtype-limits]
drivers/media/dvb-frontends/dib8000.c:3153:9: warning: comparison is always false due to limited range of data type [-Wtype-limits]
drivers/media/dvb-frontends/dib8000.c:3160:5: warning: comparison is always false

It should also be noticed that ARIB STD-B31, item
"3.15.6.8 Number of segments" at TMCC table defines the
value 15 for unused segment, and 14 as reserved.

So, better to change the check to consider any value
bigger than 13 to mean that sub-channels should be
disabled, fixing the warning and doing the right thing
even if an invalid value is filled by userspace.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# c82056d0 25-Apr-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: store dtv_property_cache in a temp var

dtv_property_cache is used on several places on very long lines.

On all places it is used, a long list of struct reference is done.

Instead of doing it, at the routines where it is used more than once,
replace it by one temporary var. That may help the compiler to
use a better code. It also makes easier to review the code, as the
lines becomes closer to 80 columns, making them a way clearer
to read.

No functional changes.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 6f7ee06f 25-Apr-2013 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] dib8000: warning fix: declare internal functions as static

drivers/media/dvb-frontends/dib8000.c:2412:5: warning: no previous prototype for 'dib8000_wait_lock' [-Wmissing-prototypes]
drivers/media/dvb-frontends/dib8000.c:2688:5: warning: no previous prototype for 'dib8000_get_symbol_duration' [-Wmissing-prototypes]

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 173a64cb 21-Apr-2013 Patrick Boettcher <pboettcher@kernellabs.com>

[media] dib8000: enhancement

The intend of this patch is to improve the support of the dib8000.

Signed-off-by: Olivier Grenie <olivier.grenie@parrot.com>
Signed-off-by: Patrick Boettcher <patrick.boettcher@parrot.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>


# 9a0bf528 13-Aug-2012 Mauro Carvalho Chehab <mchehab@kernel.org>

[media] move the dvb/frontends to drivers/media/dvb-frontends

Raise the DVB frontends one level up, as the intention is to remove
the drivers/media/dvb directory.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>