drivers/media/pci/cx88/cx88-dsp.c

Source file repositories/reference/linux-study-clean/drivers/media/pci/cx88/cx88-dsp.c

File Facts

System
Linux kernel
Corpus path
drivers/media/pci/cx88/cx88-dsp.c
Extension
.c
Size
8294 bytes
Lines
324
Domain
Driver Families
Bucket
drivers/media
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 *  Stereo and SAP detection for cx88
 *
 *  Copyright (c) 2009 Marton Balint <cus@fazekas.hu>
 */

#include "cx88.h"
#include "cx88-reg.h"

#include <linux/slab.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/jiffies.h>
#include <asm/div64.h>

#define INT_PI			((s32)(3.141592653589 * 32768.0))

#define compat_remainder(a, b) \
	 ((float)(((s32)((a) * 100)) % ((s32)((b) * 100))) / 100.0)

#define baseband_freq(carrier, srate, tone) ((s32)( \
	 (compat_remainder(carrier + tone, srate)) / srate * 2 * INT_PI))

/*
 * We calculate the baseband frequencies of the carrier and the pilot tones
 * based on the sampling rate of the audio rds fifo.
 */

#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)

/*
 * The frequencies below are from the reference driver. They probably need
 * 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
 * calculate the proper baseband frequencies...
 */

#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");

#define dprintk(level, fmt, arg...) do {				\
	if (dsp_debug >= level)						\
		printk(KERN_DEBUG pr_fmt("%s: dsp:" fmt),		\
			__func__, ##arg);				\
} while (0)

static s32 int_cos(u32 x)
{
	u32 t2, t4, t6, t8;
	s32 ret;
	u16 period = x / INT_PI;

	if (period % 2)
		return -int_cos(x - INT_PI);
	x = x % INT_PI;
	if (x > INT_PI / 2)
		return -int_cos(INT_PI / 2 - (x % (INT_PI / 2)));
	/*
	 * Now x is between 0 and INT_PI/2.
	 * To calculate cos(x) we use it's Taylor polinom.
	 */
	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;
	return ret;

Annotation

Implementation Notes