2009-04-01 06:01:51 +08:00
|
|
|
/*
|
|
|
|
* Stereo and SAP detection for cx88
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Marton Balint <cus@fazekas.hu>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2016-11-13 20:07:38 +08:00
|
|
|
#include "cx88.h"
|
|
|
|
#include "cx88-reg.h"
|
|
|
|
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-04-01 06:01:51 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/jiffies.h>
|
2009-04-07 07:07:04 +08:00
|
|
|
#include <asm/div64.h>
|
2009-04-01 06:01:51 +08:00
|
|
|
|
|
|
|
#define INT_PI ((s32)(3.141592653589 * 32768.0))
|
|
|
|
|
|
|
|
#define compat_remainder(a, b) \
|
2016-10-08 04:30:40 +08:00
|
|
|
((float)(((s32)((a) * 100)) % ((s32)((b) * 100))) / 100.0)
|
2009-04-01 06:01:51 +08:00
|
|
|
|
|
|
|
#define baseband_freq(carrier, srate, tone) ((s32)( \
|
|
|
|
(compat_remainder(carrier + tone, srate)) / srate * 2 * INT_PI))
|
|
|
|
|
[media] cx88: make checkpatch.pl happy
Usually, I don't like fixing coding style issues on non-staging
drivers, as it could be a mess pretty easy, and could become like
a snow ball. That's the case of recent changes on two changesets:
they disalign some statements. Yet, a care a lot with cx88 driver,
as it was the first driver I touched at the Kernel, and I've been
maintaining it since 2005. So, several of the coding style issues
were due to my code.
Per Andrey's suggestion, I ran checkpatch.pl in strict mode, with
fixed several other issues, did some function alinments, but broke
other alinments.
So, I had to manually apply another round of manual fixes to make
sure that everything is ok, and to make checkpatch happy with
this patch.
With this patch, checkpatch.pl is now happy when called with:
./scripts/checkpatch.pl -f --max-line-length=998 --ignore PREFER_PR_LEVEL
Also, the 80-cols violations that made sense were fixed.
Checkpatch would be happier if we convert it to use dev_foo(),
but this is a more complex change.
NOTE: there are some places with msleep(1). As this driver was
written at the time that the default was to sleep at least 10ms
on such calls (e. g. CONFIG_HZ=100), I replaced those calls by
usleep_range(10000, 20000), with should be safe to avoid breakages.
Fixes: 65bc2fe86e66 ("[media] cx88: convert it to use pr_foo() macros")
Fixes: 7b61ba8ff838 ("[media] cx88: make checkpatch happier")
Suggested-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Reviewed-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-11-20 05:27:30 +08:00
|
|
|
/*
|
|
|
|
* We calculate the baseband frequencies of the carrier and the pilot tones
|
|
|
|
* based on the the sampling rate of the audio rds fifo.
|
|
|
|
*/
|
2009-04-01 06:01:51 +08:00
|
|
|
|
|
|
|
#define FREQ_A2_CARRIER baseband_freq(54687.5, 2689.36, 0.0)
|
|
|
|
#define FREQ_A2_DUAL baseband_freq(54687.5, 2689.36, 274.1)
|
|
|
|
#define FREQ_A2_STEREO baseband_freq(54687.5, 2689.36, 117.5)
|
|
|
|
|
[media] cx88: make checkpatch.pl happy
Usually, I don't like fixing coding style issues on non-staging
drivers, as it could be a mess pretty easy, and could become like
a snow ball. That's the case of recent changes on two changesets:
they disalign some statements. Yet, a care a lot with cx88 driver,
as it was the first driver I touched at the Kernel, and I've been
maintaining it since 2005. So, several of the coding style issues
were due to my code.
Per Andrey's suggestion, I ran checkpatch.pl in strict mode, with
fixed several other issues, did some function alinments, but broke
other alinments.
So, I had to manually apply another round of manual fixes to make
sure that everything is ok, and to make checkpatch happy with
this patch.
With this patch, checkpatch.pl is now happy when called with:
./scripts/checkpatch.pl -f --max-line-length=998 --ignore PREFER_PR_LEVEL
Also, the 80-cols violations that made sense were fixed.
Checkpatch would be happier if we convert it to use dev_foo(),
but this is a more complex change.
NOTE: there are some places with msleep(1). As this driver was
written at the time that the default was to sleep at least 10ms
on such calls (e. g. CONFIG_HZ=100), I replaced those calls by
usleep_range(10000, 20000), with should be safe to avoid breakages.
Fixes: 65bc2fe86e66 ("[media] cx88: convert it to use pr_foo() macros")
Fixes: 7b61ba8ff838 ("[media] cx88: make checkpatch happier")
Suggested-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Reviewed-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-11-20 05:27:30 +08:00
|
|
|
/*
|
|
|
|
* The frequencies below are from the reference driver. They probably need
|
2009-04-01 06:01:51 +08:00
|
|
|
* further adjustments, because they are not tested at all. You may even need
|
|
|
|
* to play a bit with the registers of the chip to select the proper signal
|
|
|
|
* for the input of the audio rds fifo, and measure it's sampling rate to
|
[media] cx88: make checkpatch.pl happy
Usually, I don't like fixing coding style issues on non-staging
drivers, as it could be a mess pretty easy, and could become like
a snow ball. That's the case of recent changes on two changesets:
they disalign some statements. Yet, a care a lot with cx88 driver,
as it was the first driver I touched at the Kernel, and I've been
maintaining it since 2005. So, several of the coding style issues
were due to my code.
Per Andrey's suggestion, I ran checkpatch.pl in strict mode, with
fixed several other issues, did some function alinments, but broke
other alinments.
So, I had to manually apply another round of manual fixes to make
sure that everything is ok, and to make checkpatch happy with
this patch.
With this patch, checkpatch.pl is now happy when called with:
./scripts/checkpatch.pl -f --max-line-length=998 --ignore PREFER_PR_LEVEL
Also, the 80-cols violations that made sense were fixed.
Checkpatch would be happier if we convert it to use dev_foo(),
but this is a more complex change.
NOTE: there are some places with msleep(1). As this driver was
written at the time that the default was to sleep at least 10ms
on such calls (e. g. CONFIG_HZ=100), I replaced those calls by
usleep_range(10000, 20000), with should be safe to avoid breakages.
Fixes: 65bc2fe86e66 ("[media] cx88: convert it to use pr_foo() macros")
Fixes: 7b61ba8ff838 ("[media] cx88: make checkpatch happier")
Suggested-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Reviewed-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-11-20 05:27:30 +08:00
|
|
|
* calculate the proper baseband frequencies...
|
|
|
|
*/
|
2009-04-01 06:01:51 +08:00
|
|
|
|
|
|
|
#define FREQ_A2M_CARRIER ((s32)(2.114516 * 32768.0))
|
|
|
|
#define FREQ_A2M_DUAL ((s32)(2.754916 * 32768.0))
|
|
|
|
#define FREQ_A2M_STEREO ((s32)(2.462326 * 32768.0))
|
|
|
|
|
|
|
|
#define FREQ_EIAJ_CARRIER ((s32)(1.963495 * 32768.0)) /* 5pi/8 */
|
|
|
|
#define FREQ_EIAJ_DUAL ((s32)(2.562118 * 32768.0))
|
|
|
|
#define FREQ_EIAJ_STEREO ((s32)(2.601053 * 32768.0))
|
|
|
|
|
|
|
|
#define FREQ_BTSC_DUAL ((s32)(1.963495 * 32768.0)) /* 5pi/8 */
|
|
|
|
#define FREQ_BTSC_DUAL_REF ((s32)(1.374446 * 32768.0)) /* 7pi/16 */
|
|
|
|
|
|
|
|
#define FREQ_BTSC_SAP ((s32)(2.471532 * 32768.0))
|
|
|
|
#define FREQ_BTSC_SAP_REF ((s32)(1.730072 * 32768.0))
|
|
|
|
|
|
|
|
/* The spectrum of the signal should be empty between these frequencies. */
|
|
|
|
#define FREQ_NOISE_START ((s32)(0.100000 * 32768.0))
|
|
|
|
#define FREQ_NOISE_END ((s32)(1.200000 * 32768.0))
|
|
|
|
|
|
|
|
static unsigned int dsp_debug;
|
|
|
|
module_param(dsp_debug, int, 0644);
|
|
|
|
MODULE_PARM_DESC(dsp_debug, "enable audio dsp debug messages");
|
|
|
|
|
2016-11-13 20:07:38 +08:00
|
|
|
#define dprintk(level, fmt, arg...) do { \
|
|
|
|
if (dsp_debug >= level) \
|
|
|
|
printk(KERN_DEBUG pr_fmt("%s: dsp:" fmt), \
|
|
|
|
__func__, ##arg); \
|
|
|
|
} while (0)
|
2009-04-01 06:01:51 +08:00
|
|
|
|
|
|
|
static s32 int_cos(u32 x)
|
|
|
|
{
|
|
|
|
u32 t2, t4, t6, t8;
|
|
|
|
s32 ret;
|
|
|
|
u16 period = x / INT_PI;
|
2016-11-16 16:59:49 +08:00
|
|
|
|
2009-04-01 06:01:51 +08:00
|
|
|
if (period % 2)
|
|
|
|
return -int_cos(x - INT_PI);
|
|
|
|
x = x % INT_PI;
|
2016-10-08 04:30:40 +08:00
|
|
|
if (x > INT_PI / 2)
|
|
|
|
return -int_cos(INT_PI / 2 - (x % (INT_PI / 2)));
|
[media] cx88: make checkpatch.pl happy
Usually, I don't like fixing coding style issues on non-staging
drivers, as it could be a mess pretty easy, and could become like
a snow ball. That's the case of recent changes on two changesets:
they disalign some statements. Yet, a care a lot with cx88 driver,
as it was the first driver I touched at the Kernel, and I've been
maintaining it since 2005. So, several of the coding style issues
were due to my code.
Per Andrey's suggestion, I ran checkpatch.pl in strict mode, with
fixed several other issues, did some function alinments, but broke
other alinments.
So, I had to manually apply another round of manual fixes to make
sure that everything is ok, and to make checkpatch happy with
this patch.
With this patch, checkpatch.pl is now happy when called with:
./scripts/checkpatch.pl -f --max-line-length=998 --ignore PREFER_PR_LEVEL
Also, the 80-cols violations that made sense were fixed.
Checkpatch would be happier if we convert it to use dev_foo(),
but this is a more complex change.
NOTE: there are some places with msleep(1). As this driver was
written at the time that the default was to sleep at least 10ms
on such calls (e. g. CONFIG_HZ=100), I replaced those calls by
usleep_range(10000, 20000), with should be safe to avoid breakages.
Fixes: 65bc2fe86e66 ("[media] cx88: convert it to use pr_foo() macros")
Fixes: 7b61ba8ff838 ("[media] cx88: make checkpatch happier")
Suggested-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Reviewed-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-11-20 05:27:30 +08:00
|
|
|
/*
|
|
|
|
* Now x is between 0 and INT_PI/2.
|
|
|
|
* To calculate cos(x) we use it's Taylor polinom.
|
|
|
|
*/
|
2016-10-08 04:30:40 +08:00
|
|
|
t2 = x * x / 32768 / 2;
|
|
|
|
t4 = t2 * x / 32768 * x / 32768 / 3 / 4;
|
|
|
|
t6 = t4 * x / 32768 * x / 32768 / 5 / 6;
|
|
|
|
t8 = t6 * x / 32768 * x / 32768 / 7 / 8;
|
|
|
|
ret = 32768 - t2 + t4 - t6 + t8;
|
2009-04-01 06:01:51 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 int_goertzel(s16 x[], u32 N, u32 freq)
|
|
|
|
{
|
[media] cx88: make checkpatch.pl happy
Usually, I don't like fixing coding style issues on non-staging
drivers, as it could be a mess pretty easy, and could become like
a snow ball. That's the case of recent changes on two changesets:
they disalign some statements. Yet, a care a lot with cx88 driver,
as it was the first driver I touched at the Kernel, and I've been
maintaining it since 2005. So, several of the coding style issues
were due to my code.
Per Andrey's suggestion, I ran checkpatch.pl in strict mode, with
fixed several other issues, did some function alinments, but broke
other alinments.
So, I had to manually apply another round of manual fixes to make
sure that everything is ok, and to make checkpatch happy with
this patch.
With this patch, checkpatch.pl is now happy when called with:
./scripts/checkpatch.pl -f --max-line-length=998 --ignore PREFER_PR_LEVEL
Also, the 80-cols violations that made sense were fixed.
Checkpatch would be happier if we convert it to use dev_foo(),
but this is a more complex change.
NOTE: there are some places with msleep(1). As this driver was
written at the time that the default was to sleep at least 10ms
on such calls (e. g. CONFIG_HZ=100), I replaced those calls by
usleep_range(10000, 20000), with should be safe to avoid breakages.
Fixes: 65bc2fe86e66 ("[media] cx88: convert it to use pr_foo() macros")
Fixes: 7b61ba8ff838 ("[media] cx88: make checkpatch happier")
Suggested-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Reviewed-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-11-20 05:27:30 +08:00
|
|
|
/*
|
|
|
|
* We use the Goertzel algorithm to determine the power of the
|
|
|
|
* given frequency in the signal
|
|
|
|
*/
|
2009-04-01 06:01:51 +08:00
|
|
|
s32 s_prev = 0;
|
|
|
|
s32 s_prev2 = 0;
|
2016-10-08 04:30:40 +08:00
|
|
|
s32 coeff = 2 * int_cos(freq);
|
2009-04-01 06:01:51 +08:00
|
|
|
u32 i;
|
2009-04-07 07:07:04 +08:00
|
|
|
|
|
|
|
u64 tmp;
|
|
|
|
u32 divisor;
|
|
|
|
|
2009-04-01 06:01:51 +08:00
|
|
|
for (i = 0; i < N; i++) {
|
2016-10-08 04:30:40 +08:00
|
|
|
s32 s = x[i] + ((s64)coeff * s_prev / 32768) - s_prev2;
|
2016-11-16 16:59:49 +08:00
|
|
|
|
2009-04-01 06:01:51 +08:00
|
|
|
s_prev2 = s_prev;
|
|
|
|
s_prev = s;
|
|
|
|
}
|
2009-04-07 07:07:04 +08:00
|
|
|
|
|
|
|
tmp = (s64)s_prev2 * s_prev2 + (s64)s_prev * s_prev -
|
|
|
|
(s64)coeff * s_prev2 * s_prev / 32768;
|
|
|
|
|
[media] cx88: make checkpatch.pl happy
Usually, I don't like fixing coding style issues on non-staging
drivers, as it could be a mess pretty easy, and could become like
a snow ball. That's the case of recent changes on two changesets:
they disalign some statements. Yet, a care a lot with cx88 driver,
as it was the first driver I touched at the Kernel, and I've been
maintaining it since 2005. So, several of the coding style issues
were due to my code.
Per Andrey's suggestion, I ran checkpatch.pl in strict mode, with
fixed several other issues, did some function alinments, but broke
other alinments.
So, I had to manually apply another round of manual fixes to make
sure that everything is ok, and to make checkpatch happy with
this patch.
With this patch, checkpatch.pl is now happy when called with:
./scripts/checkpatch.pl -f --max-line-length=998 --ignore PREFER_PR_LEVEL
Also, the 80-cols violations that made sense were fixed.
Checkpatch would be happier if we convert it to use dev_foo(),
but this is a more complex change.
NOTE: there are some places with msleep(1). As this driver was
written at the time that the default was to sleep at least 10ms
on such calls (e. g. CONFIG_HZ=100), I replaced those calls by
usleep_range(10000, 20000), with should be safe to avoid breakages.
Fixes: 65bc2fe86e66 ("[media] cx88: convert it to use pr_foo() macros")
Fixes: 7b61ba8ff838 ("[media] cx88: make checkpatch happier")
Suggested-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Reviewed-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-11-20 05:27:30 +08:00
|
|
|
/*
|
|
|
|
* XXX: N must be low enough so that N*N fits in s32.
|
|
|
|
* Else we need two divisions.
|
|
|
|
*/
|
2009-04-07 07:07:04 +08:00
|
|
|
divisor = N * N;
|
|
|
|
do_div(tmp, divisor);
|
|
|
|
|
[media] cx88: make checkpatch.pl happy
Usually, I don't like fixing coding style issues on non-staging
drivers, as it could be a mess pretty easy, and could become like
a snow ball. That's the case of recent changes on two changesets:
they disalign some statements. Yet, a care a lot with cx88 driver,
as it was the first driver I touched at the Kernel, and I've been
maintaining it since 2005. So, several of the coding style issues
were due to my code.
Per Andrey's suggestion, I ran checkpatch.pl in strict mode, with
fixed several other issues, did some function alinments, but broke
other alinments.
So, I had to manually apply another round of manual fixes to make
sure that everything is ok, and to make checkpatch happy with
this patch.
With this patch, checkpatch.pl is now happy when called with:
./scripts/checkpatch.pl -f --max-line-length=998 --ignore PREFER_PR_LEVEL
Also, the 80-cols violations that made sense were fixed.
Checkpatch would be happier if we convert it to use dev_foo(),
but this is a more complex change.
NOTE: there are some places with msleep(1). As this driver was
written at the time that the default was to sleep at least 10ms
on such calls (e. g. CONFIG_HZ=100), I replaced those calls by
usleep_range(10000, 20000), with should be safe to avoid breakages.
Fixes: 65bc2fe86e66 ("[media] cx88: convert it to use pr_foo() macros")
Fixes: 7b61ba8ff838 ("[media] cx88: make checkpatch happier")
Suggested-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Reviewed-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-11-20 05:27:30 +08:00
|
|
|
return (u32)tmp;
|
2009-04-01 06:01:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static u32 freq_magnitude(s16 x[], u32 N, u32 freq)
|
|
|
|
{
|
|
|
|
u32 sum = int_goertzel(x, N, freq);
|
2016-11-16 16:59:49 +08:00
|
|
|
|
2009-04-01 06:01:51 +08:00
|
|
|
return (u32)int_sqrt(sum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 noise_magnitude(s16 x[], u32 N, u32 freq_start, u32 freq_end)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u32 sum = 0;
|
|
|
|
u32 freq_step;
|
|
|
|
int samples = 5;
|
|
|
|
|
|
|
|
if (N > 192) {
|
|
|
|
/* The last 192 samples are enough for noise detection */
|
2016-10-08 04:30:40 +08:00
|
|
|
x += (N - 192);
|
2009-04-01 06:01:51 +08:00
|
|
|
N = 192;
|
|
|
|
}
|
|
|
|
|
|
|
|
freq_step = (freq_end - freq_start) / (samples - 1);
|
|
|
|
|
|
|
|
for (i = 0; i < samples; i++) {
|
|
|
|
sum += int_goertzel(x, N, freq_start);
|
|
|
|
freq_start += freq_step;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (u32)int_sqrt(sum / samples);
|
|
|
|
}
|
|
|
|
|
|
|
|
static s32 detect_a2_a2m_eiaj(struct cx88_core *core, s16 x[], u32 N)
|
|
|
|
{
|
|
|
|
s32 carrier, stereo, dual, noise;
|
|
|
|
s32 carrier_freq, stereo_freq, dual_freq;
|
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
switch (core->tvaudio) {
|
|
|
|
case WW_BG:
|
|
|
|
case WW_DK:
|
|
|
|
carrier_freq = FREQ_A2_CARRIER;
|
|
|
|
stereo_freq = FREQ_A2_STEREO;
|
|
|
|
dual_freq = FREQ_A2_DUAL;
|
|
|
|
break;
|
|
|
|
case WW_M:
|
|
|
|
carrier_freq = FREQ_A2M_CARRIER;
|
|
|
|
stereo_freq = FREQ_A2M_STEREO;
|
|
|
|
dual_freq = FREQ_A2M_DUAL;
|
|
|
|
break;
|
|
|
|
case WW_EIAJ:
|
|
|
|
carrier_freq = FREQ_EIAJ_CARRIER;
|
|
|
|
stereo_freq = FREQ_EIAJ_STEREO;
|
|
|
|
dual_freq = FREQ_EIAJ_DUAL;
|
|
|
|
break;
|
2010-09-08 21:14:51 +08:00
|
|
|
default:
|
2016-11-13 20:07:38 +08:00
|
|
|
pr_warn("unsupported audio mode %d for %s\n",
|
|
|
|
core->tvaudio, __func__);
|
2009-04-01 06:01:51 +08:00
|
|
|
return UNSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
carrier = freq_magnitude(x, N, carrier_freq);
|
|
|
|
stereo = freq_magnitude(x, N, stereo_freq);
|
|
|
|
dual = freq_magnitude(x, N, dual_freq);
|
|
|
|
noise = noise_magnitude(x, N, FREQ_NOISE_START, FREQ_NOISE_END);
|
|
|
|
|
[media] cx88: make checkpatch.pl happy
Usually, I don't like fixing coding style issues on non-staging
drivers, as it could be a mess pretty easy, and could become like
a snow ball. That's the case of recent changes on two changesets:
they disalign some statements. Yet, a care a lot with cx88 driver,
as it was the first driver I touched at the Kernel, and I've been
maintaining it since 2005. So, several of the coding style issues
were due to my code.
Per Andrey's suggestion, I ran checkpatch.pl in strict mode, with
fixed several other issues, did some function alinments, but broke
other alinments.
So, I had to manually apply another round of manual fixes to make
sure that everything is ok, and to make checkpatch happy with
this patch.
With this patch, checkpatch.pl is now happy when called with:
./scripts/checkpatch.pl -f --max-line-length=998 --ignore PREFER_PR_LEVEL
Also, the 80-cols violations that made sense were fixed.
Checkpatch would be happier if we convert it to use dev_foo(),
but this is a more complex change.
NOTE: there are some places with msleep(1). As this driver was
written at the time that the default was to sleep at least 10ms
on such calls (e. g. CONFIG_HZ=100), I replaced those calls by
usleep_range(10000, 20000), with should be safe to avoid breakages.
Fixes: 65bc2fe86e66 ("[media] cx88: convert it to use pr_foo() macros")
Fixes: 7b61ba8ff838 ("[media] cx88: make checkpatch happier")
Suggested-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Reviewed-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-11-20 05:27:30 +08:00
|
|
|
dprintk(1,
|
|
|
|
"detect a2/a2m/eiaj: carrier=%d, stereo=%d, dual=%d, noise=%d\n",
|
[media] cx88: don't break long lines
Due to the 80-cols restrictions, and latter due to checkpatch
warnings, several strings were broken into multiple lines. This
is not considered a good practice anymore, as it makes harder
to grep for strings at the source code.
As we're right now fixing other drivers due to KERN_CONT, we need
to be able to identify what printk strings don't end with a "\n".
It is a way easier to detect those if we don't break long lines.
So, join those continuation lines.
The patch was generated via the script below, and manually
adjusted if needed.
</script>
use Text::Tabs;
while (<>) {
if ($next ne "") {
$c=$_;
if ($c =~ /^\s+\"(.*)/) {
$c2=$1;
$next =~ s/\"\n$//;
$n = expand($next);
$funpos = index($n, '(');
$pos = index($c2, '",');
if ($funpos && $pos > 0) {
$s1 = substr $c2, 0, $pos + 2;
$s2 = ' ' x ($funpos + 1) . substr $c2, $pos + 2;
$s2 =~ s/^\s+//;
$s2 = ' ' x ($funpos + 1) . $s2 if ($s2 ne "");
print unexpand("$next$s1\n");
print unexpand("$s2\n") if ($s2 ne "");
} else {
print "$next$c2\n";
}
$next="";
next;
} else {
print $next;
}
$next="";
} else {
if (m/\"$/) {
if (!m/\\n\"$/) {
$next=$_;
next;
}
}
}
print $_;
}
</script>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-10-19 03:44:04 +08:00
|
|
|
carrier, stereo, dual, noise);
|
2009-04-01 06:01:51 +08:00
|
|
|
|
|
|
|
if (stereo > dual)
|
|
|
|
ret = V4L2_TUNER_SUB_STEREO;
|
|
|
|
else
|
|
|
|
ret = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
|
|
|
|
|
|
|
|
if (core->tvaudio == WW_EIAJ) {
|
|
|
|
/* EIAJ checks may need adjustments */
|
2016-10-08 04:30:40 +08:00
|
|
|
if ((carrier > max(stereo, dual) * 2) &&
|
|
|
|
(carrier < max(stereo, dual) * 6) &&
|
2009-04-01 06:01:51 +08:00
|
|
|
(carrier > 20 && carrier < 200) &&
|
|
|
|
(max(stereo, dual) > min(stereo, dual))) {
|
[media] cx88: make checkpatch.pl happy
Usually, I don't like fixing coding style issues on non-staging
drivers, as it could be a mess pretty easy, and could become like
a snow ball. That's the case of recent changes on two changesets:
they disalign some statements. Yet, a care a lot with cx88 driver,
as it was the first driver I touched at the Kernel, and I've been
maintaining it since 2005. So, several of the coding style issues
were due to my code.
Per Andrey's suggestion, I ran checkpatch.pl in strict mode, with
fixed several other issues, did some function alinments, but broke
other alinments.
So, I had to manually apply another round of manual fixes to make
sure that everything is ok, and to make checkpatch happy with
this patch.
With this patch, checkpatch.pl is now happy when called with:
./scripts/checkpatch.pl -f --max-line-length=998 --ignore PREFER_PR_LEVEL
Also, the 80-cols violations that made sense were fixed.
Checkpatch would be happier if we convert it to use dev_foo(),
but this is a more complex change.
NOTE: there are some places with msleep(1). As this driver was
written at the time that the default was to sleep at least 10ms
on such calls (e. g. CONFIG_HZ=100), I replaced those calls by
usleep_range(10000, 20000), with should be safe to avoid breakages.
Fixes: 65bc2fe86e66 ("[media] cx88: convert it to use pr_foo() macros")
Fixes: 7b61ba8ff838 ("[media] cx88: make checkpatch happier")
Suggested-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Reviewed-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-11-20 05:27:30 +08:00
|
|
|
/*
|
|
|
|
* For EIAJ the carrier is always present,
|
|
|
|
* so we probably don't need noise detection
|
|
|
|
*/
|
2009-04-01 06:01:51 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} else {
|
2016-10-08 04:30:40 +08:00
|
|
|
if ((carrier > max(stereo, dual) * 2) &&
|
|
|
|
(carrier < max(stereo, dual) * 8) &&
|
2009-04-01 06:01:51 +08:00
|
|
|
(carrier > 20 && carrier < 200) &&
|
|
|
|
(noise < 10) &&
|
2016-10-08 04:30:40 +08:00
|
|
|
(max(stereo, dual) > min(stereo, dual) * 2)) {
|
2009-04-01 06:01:51 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return V4L2_TUNER_SUB_MONO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static s32 detect_btsc(struct cx88_core *core, s16 x[], u32 N)
|
|
|
|
{
|
|
|
|
s32 sap_ref = freq_magnitude(x, N, FREQ_BTSC_SAP_REF);
|
|
|
|
s32 sap = freq_magnitude(x, N, FREQ_BTSC_SAP);
|
|
|
|
s32 dual_ref = freq_magnitude(x, N, FREQ_BTSC_DUAL_REF);
|
|
|
|
s32 dual = freq_magnitude(x, N, FREQ_BTSC_DUAL);
|
2016-11-16 16:59:49 +08:00
|
|
|
|
[media] cx88: don't break long lines
Due to the 80-cols restrictions, and latter due to checkpatch
warnings, several strings were broken into multiple lines. This
is not considered a good practice anymore, as it makes harder
to grep for strings at the source code.
As we're right now fixing other drivers due to KERN_CONT, we need
to be able to identify what printk strings don't end with a "\n".
It is a way easier to detect those if we don't break long lines.
So, join those continuation lines.
The patch was generated via the script below, and manually
adjusted if needed.
</script>
use Text::Tabs;
while (<>) {
if ($next ne "") {
$c=$_;
if ($c =~ /^\s+\"(.*)/) {
$c2=$1;
$next =~ s/\"\n$//;
$n = expand($next);
$funpos = index($n, '(');
$pos = index($c2, '",');
if ($funpos && $pos > 0) {
$s1 = substr $c2, 0, $pos + 2;
$s2 = ' ' x ($funpos + 1) . substr $c2, $pos + 2;
$s2 =~ s/^\s+//;
$s2 = ' ' x ($funpos + 1) . $s2 if ($s2 ne "");
print unexpand("$next$s1\n");
print unexpand("$s2\n") if ($s2 ne "");
} else {
print "$next$c2\n";
}
$next="";
next;
} else {
print $next;
}
$next="";
} else {
if (m/\"$/) {
if (!m/\\n\"$/) {
$next=$_;
next;
}
}
}
print $_;
}
</script>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-10-19 03:44:04 +08:00
|
|
|
dprintk(1, "detect btsc: dual_ref=%d, dual=%d, sap_ref=%d, sap=%d\n",
|
|
|
|
dual_ref, dual, sap_ref, sap);
|
2009-04-01 06:01:51 +08:00
|
|
|
/* FIXME: Currently not supported */
|
|
|
|
return UNSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
static s16 *read_rds_samples(struct cx88_core *core, u32 *N)
|
|
|
|
{
|
2010-08-25 20:50:20 +08:00
|
|
|
const struct sram_channel *srch = &cx88_sram_channels[SRAM_CH27];
|
2009-04-01 06:01:51 +08:00
|
|
|
s16 *samples;
|
|
|
|
|
|
|
|
unsigned int i;
|
2016-10-08 04:30:40 +08:00
|
|
|
unsigned int bpl = srch->fifo_size / AUD_RDS_LINES;
|
|
|
|
unsigned int spl = bpl / 4;
|
|
|
|
unsigned int sample_count = spl * (AUD_RDS_LINES - 1);
|
2009-04-01 06:01:51 +08:00
|
|
|
|
|
|
|
u32 current_address = cx_read(srch->ptr1_reg);
|
|
|
|
u32 offset = (current_address - srch->fifo_start + bpl);
|
|
|
|
|
[media] cx88: make checkpatch.pl happy
Usually, I don't like fixing coding style issues on non-staging
drivers, as it could be a mess pretty easy, and could become like
a snow ball. That's the case of recent changes on two changesets:
they disalign some statements. Yet, a care a lot with cx88 driver,
as it was the first driver I touched at the Kernel, and I've been
maintaining it since 2005. So, several of the coding style issues
were due to my code.
Per Andrey's suggestion, I ran checkpatch.pl in strict mode, with
fixed several other issues, did some function alinments, but broke
other alinments.
So, I had to manually apply another round of manual fixes to make
sure that everything is ok, and to make checkpatch happy with
this patch.
With this patch, checkpatch.pl is now happy when called with:
./scripts/checkpatch.pl -f --max-line-length=998 --ignore PREFER_PR_LEVEL
Also, the 80-cols violations that made sense were fixed.
Checkpatch would be happier if we convert it to use dev_foo(),
but this is a more complex change.
NOTE: there are some places with msleep(1). As this driver was
written at the time that the default was to sleep at least 10ms
on such calls (e. g. CONFIG_HZ=100), I replaced those calls by
usleep_range(10000, 20000), with should be safe to avoid breakages.
Fixes: 65bc2fe86e66 ("[media] cx88: convert it to use pr_foo() macros")
Fixes: 7b61ba8ff838 ("[media] cx88: make checkpatch happier")
Suggested-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Reviewed-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-11-20 05:27:30 +08:00
|
|
|
dprintk(1,
|
|
|
|
"read RDS samples: current_address=%08x (offset=%08x), sample_count=%d, aud_intstat=%08x\n",
|
[media] cx88: don't break long lines
Due to the 80-cols restrictions, and latter due to checkpatch
warnings, several strings were broken into multiple lines. This
is not considered a good practice anymore, as it makes harder
to grep for strings at the source code.
As we're right now fixing other drivers due to KERN_CONT, we need
to be able to identify what printk strings don't end with a "\n".
It is a way easier to detect those if we don't break long lines.
So, join those continuation lines.
The patch was generated via the script below, and manually
adjusted if needed.
</script>
use Text::Tabs;
while (<>) {
if ($next ne "") {
$c=$_;
if ($c =~ /^\s+\"(.*)/) {
$c2=$1;
$next =~ s/\"\n$//;
$n = expand($next);
$funpos = index($n, '(');
$pos = index($c2, '",');
if ($funpos && $pos > 0) {
$s1 = substr $c2, 0, $pos + 2;
$s2 = ' ' x ($funpos + 1) . substr $c2, $pos + 2;
$s2 =~ s/^\s+//;
$s2 = ' ' x ($funpos + 1) . $s2 if ($s2 ne "");
print unexpand("$next$s1\n");
print unexpand("$s2\n") if ($s2 ne "");
} else {
print "$next$c2\n";
}
$next="";
next;
} else {
print $next;
}
$next="";
} else {
if (m/\"$/) {
if (!m/\\n\"$/) {
$next=$_;
next;
}
}
}
print $_;
}
</script>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-10-19 03:44:04 +08:00
|
|
|
current_address,
|
2009-04-01 06:01:51 +08:00
|
|
|
current_address - srch->fifo_start, sample_count,
|
|
|
|
cx_read(MO_AUD_INTSTAT));
|
2016-10-08 04:07:27 +08:00
|
|
|
samples = kmalloc_array(sample_count, sizeof(*samples), GFP_KERNEL);
|
2009-04-01 06:01:51 +08:00
|
|
|
if (!samples)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*N = sample_count;
|
|
|
|
|
|
|
|
for (i = 0; i < sample_count; i++) {
|
2016-10-08 04:30:40 +08:00
|
|
|
offset = offset % (AUD_RDS_LINES * bpl);
|
2009-04-01 06:01:51 +08:00
|
|
|
samples[i] = cx_read(srch->fifo_start + offset);
|
|
|
|
offset += 4;
|
|
|
|
}
|
|
|
|
|
2016-10-14 17:58:14 +08:00
|
|
|
dprintk(2, "RDS samples dump: %*ph\n", sample_count, samples);
|
2009-04-01 06:01:51 +08:00
|
|
|
|
|
|
|
return samples;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 cx88_dsp_detect_stereo_sap(struct cx88_core *core)
|
|
|
|
{
|
|
|
|
s16 *samples;
|
|
|
|
u32 N = 0;
|
|
|
|
s32 ret = UNSET;
|
|
|
|
|
|
|
|
/* If audio RDS fifo is disabled, we can't read the samples */
|
|
|
|
if (!(cx_read(MO_AUD_DMACNTRL) & 0x04))
|
|
|
|
return ret;
|
|
|
|
if (!(cx_read(AUD_CTL) & EN_FMRADIO_EN_RDS))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Wait at least 500 ms after an audio standard change */
|
|
|
|
if (time_before(jiffies, core->last_change + msecs_to_jiffies(500)))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
samples = read_rds_samples(core, &N);
|
|
|
|
|
|
|
|
if (!samples)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
switch (core->tvaudio) {
|
|
|
|
case WW_BG:
|
|
|
|
case WW_DK:
|
2010-08-23 18:49:58 +08:00
|
|
|
case WW_EIAJ:
|
|
|
|
case WW_M:
|
2009-04-01 06:01:51 +08:00
|
|
|
ret = detect_a2_a2m_eiaj(core, samples, N);
|
|
|
|
break;
|
|
|
|
case WW_BTSC:
|
|
|
|
ret = detect_btsc(core, samples, N);
|
|
|
|
break;
|
2010-08-23 18:49:58 +08:00
|
|
|
case WW_NONE:
|
|
|
|
case WW_I:
|
|
|
|
case WW_L:
|
|
|
|
case WW_I2SPT:
|
|
|
|
case WW_FM:
|
|
|
|
case WW_I2SADC:
|
|
|
|
break;
|
2009-04-01 06:01:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
kfree(samples);
|
|
|
|
|
2016-11-16 16:59:49 +08:00
|
|
|
if (ret != UNSET)
|
2009-04-01 06:01:51 +08:00
|
|
|
dprintk(1, "stereo/sap detection result:%s%s%s\n",
|
[media] cx88: make checkpatch.pl happy
Usually, I don't like fixing coding style issues on non-staging
drivers, as it could be a mess pretty easy, and could become like
a snow ball. That's the case of recent changes on two changesets:
they disalign some statements. Yet, a care a lot with cx88 driver,
as it was the first driver I touched at the Kernel, and I've been
maintaining it since 2005. So, several of the coding style issues
were due to my code.
Per Andrey's suggestion, I ran checkpatch.pl in strict mode, with
fixed several other issues, did some function alinments, but broke
other alinments.
So, I had to manually apply another round of manual fixes to make
sure that everything is ok, and to make checkpatch happy with
this patch.
With this patch, checkpatch.pl is now happy when called with:
./scripts/checkpatch.pl -f --max-line-length=998 --ignore PREFER_PR_LEVEL
Also, the 80-cols violations that made sense were fixed.
Checkpatch would be happier if we convert it to use dev_foo(),
but this is a more complex change.
NOTE: there are some places with msleep(1). As this driver was
written at the time that the default was to sleep at least 10ms
on such calls (e. g. CONFIG_HZ=100), I replaced those calls by
usleep_range(10000, 20000), with should be safe to avoid breakages.
Fixes: 65bc2fe86e66 ("[media] cx88: convert it to use pr_foo() macros")
Fixes: 7b61ba8ff838 ("[media] cx88: make checkpatch happier")
Suggested-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Reviewed-by: Andrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-11-20 05:27:30 +08:00
|
|
|
(ret & V4L2_TUNER_SUB_MONO) ? " mono" : "",
|
|
|
|
(ret & V4L2_TUNER_SUB_STEREO) ? " stereo" : "",
|
|
|
|
(ret & V4L2_TUNER_SUB_LANG2) ? " dual" : "");
|
2009-04-01 06:01:51 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(cx88_dsp_detect_stereo_sap);
|
|
|
|
|