Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 399426ca authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab
Browse files

[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: 65bc2fe8 ("[media] cx88: convert it to use pr_foo() macros")
Fixes: 7b61ba8f ("[media] cx88: make checkpatch happier")

Suggested-by: default avatarAndrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
Reviewed-by: default avatarAndrey Utkin <andrey_utkin@fastmail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 1d389714
Loading
Loading
Loading
Loading
+105 −101
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@

#include <linux/module.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/interrupt.h>
#include <linux/vmalloc.h>
@@ -31,7 +32,6 @@
#include <linux/pci.h>
#include <linux/slab.h>

#include <asm/delay.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
@@ -46,9 +46,9 @@
			chip->core->name, ##arg);			\
} while (0)

/****************************************************************************
	Data type declarations - Can be moded to a header file later
 ****************************************************************************/
/*
 * Data type declarations - Can be moded to a header file later
 */

struct cx88_audio_buffer {
	unsigned int               bpl;
@@ -82,13 +82,10 @@ struct cx88_audio_dev {

	struct snd_pcm_substream   *substream;
};
typedef struct cx88_audio_dev snd_cx88_card_t;



/****************************************************************************
			Module global static vars
 ****************************************************************************/
/*
 * Module global static vars
 */

static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
static const char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
@@ -100,10 +97,9 @@ MODULE_PARM_DESC(enable, "Enable cx88x soundcard. default enabled.");
module_param_array(index, int, NULL, 0444);
MODULE_PARM_DESC(index, "Index value for cx88x capture interface(s).");


/****************************************************************************
				Module macros
 ****************************************************************************/
/*
 * Module macros
 */

MODULE_DESCRIPTION("ALSA driver module for cx2388x based TV cards");
MODULE_AUTHOR("Ricardo Cerqueira");
@@ -116,15 +112,15 @@ static unsigned int debug;
module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "enable debug messages");

/****************************************************************************
			Module specific funtions
 ****************************************************************************/
/*
 * Module specific functions
 */

/*
 * BOARD Specific: Sets audio DMA
 */

static int _cx88_start_audio_dma(snd_cx88_card_t *chip)
static int _cx88_start_audio_dma(struct cx88_audio_dev *chip)
{
	struct cx88_audio_buffer *buf = chip->buf;
	struct cx88_core *core = chip->core;
@@ -143,7 +139,8 @@ static int _cx88_start_audio_dma(snd_cx88_card_t *chip)
	cx_write(MO_AUDD_GPCNTRL, GP_COUNT_CONTROL_RESET);
	atomic_set(&chip->count, 0);

	dprintk(1, "Start audio DMA, %d B/line, %d lines/FIFO, %d periods, %d byte buffer\n",
	dprintk(1,
		"Start audio DMA, %d B/line, %d lines/FIFO, %d periods, %d byte buffer\n",
		buf->bpl, cx_read(audio_ch->cmds_start + 8) >> 1,
		chip->num_periods, buf->bpl * chip->num_periods);

@@ -158,8 +155,11 @@ static int _cx88_start_audio_dma(snd_cx88_card_t *chip)
	cx_set(MO_PCI_INTMSK, chip->core->pci_irqmask | PCI_INT_AUDINT);

	/* start dma */
	cx_set(MO_DEV_CNTRL2, (1<<5)); /* Enables Risc Processor */
	cx_set(MO_AUD_DMACNTRL, 0x11); /* audio downstream FIFO and RISC enable */

	/* Enables Risc Processor */
	cx_set(MO_DEV_CNTRL2, (1 << 5));
	/* audio downstream FIFO and RISC enable */
	cx_set(MO_AUD_DMACNTRL, 0x11);

	if (debug)
		cx88_sram_channel_dump(chip->core, audio_ch);
@@ -170,7 +170,7 @@ static int _cx88_start_audio_dma(snd_cx88_card_t *chip)
/*
 * BOARD Specific: Resets audio DMA
 */
static int _cx88_stop_audio_dma(snd_cx88_card_t *chip)
static int _cx88_stop_audio_dma(struct cx88_audio_dev *chip)
{
	struct cx88_core *core = chip->core;

@@ -185,7 +185,8 @@ static int _cx88_stop_audio_dma(snd_cx88_card_t *chip)
				AUD_INT_DN_RISCI2 | AUD_INT_DN_RISCI1);

	if (debug)
		cx88_sram_channel_dump(chip->core, &cx88_sram_channels[SRAM_CH25]);
		cx88_sram_channel_dump(chip->core,
				       &cx88_sram_channels[SRAM_CH25]);

	return 0;
}
@@ -211,7 +212,7 @@ static const char *cx88_aud_irqs[32] = {
/*
 * BOARD Specific: Threats IRQ audio specific calls
 */
static void cx8801_aud_irq(snd_cx88_card_t *chip)
static void cx8801_aud_irq(struct cx88_audio_dev *chip)
{
	struct cx88_core *core = chip->core;
	u32 status, mask;
@@ -249,7 +250,7 @@ static void cx8801_aud_irq(snd_cx88_card_t *chip)
 */
static irqreturn_t cx8801_irq(int irq, void *dev_id)
{
	snd_cx88_card_t *chip = dev_id;
	struct cx88_audio_dev *chip = dev_id;
	struct cx88_core *core = chip->core;
	u32 status;
	int loop, handled = 0;
@@ -286,26 +287,25 @@ static int cx88_alsa_dma_init(struct cx88_audio_dev *chip, int nr_pages)
	int i;

	buf->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT);
	if (buf->vaddr == NULL) {
	if (!buf->vaddr) {
		dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages);
		return -ENOMEM;
	}

	dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n",
				(unsigned long)buf->vaddr,
				nr_pages << PAGE_SHIFT);
		(unsigned long)buf->vaddr, nr_pages << PAGE_SHIFT);

	memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT);
	buf->nr_pages = nr_pages;

	buf->sglist = vzalloc(buf->nr_pages * sizeof(*buf->sglist));
	if (buf->sglist == NULL)
	if (!buf->sglist)
		goto vzalloc_err;

	sg_init_table(buf->sglist, buf->nr_pages);
	for (i = 0; i < buf->nr_pages; i++) {
		pg = vmalloc_to_page(buf->vaddr + i * PAGE_SIZE);
		if (pg == NULL)
		if (!pg)
			goto vmalloc_to_page_err;
		sg_set_page(&buf->sglist[i], pg, PAGE_SIZE, 0);
	}
@@ -341,7 +341,8 @@ static int cx88_alsa_dma_unmap(struct cx88_audio_dev *dev)
	if (!buf->sglen)
		return 0;

	dma_unmap_sg(&dev->pci->dev, buf->sglist, buf->sglen, PCI_DMA_FROMDEVICE);
	dma_unmap_sg(&dev->pci->dev, buf->sglist, buf->sglen,
		     PCI_DMA_FROMDEVICE);
	buf->sglen = 0;
	return 0;
}
@@ -355,18 +356,18 @@ static int cx88_alsa_dma_free(struct cx88_audio_buffer *buf)
	return 0;
}


static int dsp_buffer_free(snd_cx88_card_t *chip)
static int dsp_buffer_free(struct cx88_audio_dev *chip)
{
	struct cx88_riscmem *risc = &chip->buf->risc;

	BUG_ON(!chip->dma_size);
	WARN_ON(!chip->dma_size);

	dprintk(2, "Freeing buffer\n");
	cx88_alsa_dma_unmap(chip);
	cx88_alsa_dma_free(chip->buf);
	if (risc->cpu)
		pci_free_consistent(chip->pci, risc->size, risc->cpu, risc->dma);
		pci_free_consistent(chip->pci, risc->size,
				    risc->cpu, risc->dma);
	kfree(chip->buf);

	chip->buf = NULL;
@@ -374,9 +375,9 @@ static int dsp_buffer_free(snd_cx88_card_t *chip)
	return 0;
}

/****************************************************************************
				ALSA PCM Interface
 ****************************************************************************/
/*
 * ALSA PCM Interface
 */

/*
 * Digital hardware definition
@@ -394,8 +395,10 @@ static const struct snd_pcm_hardware snd_cx88_digital_hw = {
	.rate_max =		48000,
	.channels_min = 2,
	.channels_max = 2,
	/* Analog audio output will be full of clicks and pops if there
	   are not exactly four lines in the SRAM FIFO buffer.  */
	/*
	 * Analog audio output will be full of clicks and pops if there
	 * are not exactly four lines in the SRAM FIFO buffer.
	 */
	.period_bytes_min = DEFAULT_FIFO_SIZE / 4,
	.period_bytes_max = DEFAULT_FIFO_SIZE / 4,
	.periods_min = 1,
@@ -408,7 +411,7 @@ static const struct snd_pcm_hardware snd_cx88_digital_hw = {
 */
static int snd_cx88_pcm_open(struct snd_pcm_substream *substream)
{
	snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
	struct cx88_audio_dev *chip = snd_pcm_substream_chip(substream);
	struct snd_pcm_runtime *runtime = substream->runtime;
	int err;

@@ -417,7 +420,8 @@ static int snd_cx88_pcm_open(struct snd_pcm_substream *substream)
		return -ENODEV;
	}

	err = snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIODS);
	err = snd_pcm_hw_constraint_pow2(runtime, 0,
					 SNDRV_PCM_HW_PARAM_PERIODS);
	if (err < 0)
		goto _error;

@@ -453,7 +457,7 @@ static int snd_cx88_close(struct snd_pcm_substream *substream)
static int snd_cx88_hw_params(struct snd_pcm_substream *substream,
			      struct snd_pcm_hw_params *hw_params)
{
	snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
	struct cx88_audio_dev *chip = snd_pcm_substream_chip(substream);

	struct cx88_audio_buffer *buf;
	int ret;
@@ -467,11 +471,11 @@ static int snd_cx88_hw_params(struct snd_pcm_substream *substream,
	chip->num_periods = params_periods(hw_params);
	chip->dma_size = chip->period_size * params_periods(hw_params);

	BUG_ON(!chip->dma_size);
	BUG_ON(chip->num_periods & (chip->num_periods-1));
	WARN_ON(!chip->dma_size);
	WARN_ON(chip->num_periods & (chip->num_periods - 1));

	buf = kzalloc(sizeof(*buf), GFP_KERNEL);
	if (buf == NULL)
	if (!buf)
		return -ENOMEM;

	chip->buf = buf;
@@ -510,8 +514,7 @@ static int snd_cx88_hw_params(struct snd_pcm_substream *substream,
 */
static int snd_cx88_hw_free(struct snd_pcm_substream *substream)
{

	snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
	struct cx88_audio_dev *chip = snd_pcm_substream_chip(substream);

	if (substream->runtime->dma_area) {
		dsp_buffer_free(chip);
@@ -534,7 +537,7 @@ static int snd_cx88_prepare(struct snd_pcm_substream *substream)
 */
static int snd_cx88_card_trigger(struct snd_pcm_substream *substream, int cmd)
{
	snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
	struct cx88_audio_dev *chip = snd_pcm_substream_chip(substream);
	int err;

	/* Local interrupts are already disabled by ALSA */
@@ -562,7 +565,7 @@ static int snd_cx88_card_trigger(struct snd_pcm_substream *substream, int cmd)
 */
static snd_pcm_uframes_t snd_cx88_pointer(struct snd_pcm_substream *substream)
{
	snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
	struct cx88_audio_dev *chip = snd_pcm_substream_chip(substream);
	struct snd_pcm_runtime *runtime = substream->runtime;
	u16 count;

@@ -603,7 +606,8 @@ static const struct snd_pcm_ops snd_cx88_pcm_ops = {
/*
 * create a PCM device
 */
static int snd_cx88_pcm(snd_cx88_card_t *chip, int device, const char *name)
static int snd_cx88_pcm(struct cx88_audio_dev *chip, int device,
			const char *name)
{
	int err;
	struct snd_pcm *pcm;
@@ -618,9 +622,9 @@ static int snd_cx88_pcm(snd_cx88_card_t *chip, int device, const char *name)
	return 0;
}

/****************************************************************************
				CONTROL INTERFACE
 ****************************************************************************/
/*
 * CONTROL INTERFACE
 */
static int snd_cx88_volume_info(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_info *info)
{
@@ -635,7 +639,7 @@ static int snd_cx88_volume_info(struct snd_kcontrol *kcontrol,
static int snd_cx88_volume_get(struct snd_kcontrol *kcontrol,
			       struct snd_ctl_elem_value *value)
{
	snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
	struct cx88_audio_dev *chip = snd_kcontrol_chip(kcontrol);
	struct cx88_core *core = chip->core;
	int vol = 0x3f - (cx_read(AUD_VOL_CTL) & 0x3f),
	    bal = cx_read(AUD_BAL_CTL);
@@ -650,7 +654,7 @@ static int snd_cx88_volume_get(struct snd_kcontrol *kcontrol,
static void snd_cx88_wm8775_volume_put(struct snd_kcontrol *kcontrol,
				       struct snd_ctl_elem_value *value)
{
	snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
	struct cx88_audio_dev *chip = snd_kcontrol_chip(kcontrol);
	struct cx88_core *core = chip->core;
	int left = value->value.integer.value[0];
	int right = value->value.integer.value[1];
@@ -672,7 +676,7 @@ static void snd_cx88_wm8775_volume_put(struct snd_kcontrol *kcontrol,
static int snd_cx88_volume_put(struct snd_kcontrol *kcontrol,
			       struct snd_ctl_elem_value *value)
{
	snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
	struct cx88_audio_dev *chip = snd_kcontrol_chip(kcontrol);
	struct cx88_core *core = chip->core;
	int left, right, v, b;
	int changed = 0;
@@ -722,7 +726,7 @@ static const struct snd_kcontrol_new snd_cx88_volume = {
static int snd_cx88_switch_get(struct snd_kcontrol *kcontrol,
			       struct snd_ctl_elem_value *value)
{
	snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
	struct cx88_audio_dev *chip = snd_kcontrol_chip(kcontrol);
	struct cx88_core *core = chip->core;
	u32 bit = kcontrol->private_value;

@@ -733,7 +737,7 @@ static int snd_cx88_switch_get(struct snd_kcontrol *kcontrol,
static int snd_cx88_switch_put(struct snd_kcontrol *kcontrol,
			       struct snd_ctl_elem_value *value)
{
	snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
	struct cx88_audio_dev *chip = snd_kcontrol_chip(kcontrol);
	struct cx88_core *core = chip->core;
	u32 bit = kcontrol->private_value;
	int ret = 0;
@@ -746,7 +750,8 @@ static int snd_cx88_switch_put(struct snd_kcontrol *kcontrol,
		cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, vol);
		/* Pass mute onto any WM8775 */
		if (core->sd_wm8775 && ((1 << 6) == bit))
			wm8775_s_ctrl(core, V4L2_CID_AUDIO_MUTE, 0 != (vol & bit));
			wm8775_s_ctrl(core,
				      V4L2_CID_AUDIO_MUTE, 0 != (vol & bit));
		ret = 1;
	}
	spin_unlock_irq(&chip->reg_lock);
@@ -774,7 +779,7 @@ static const struct snd_kcontrol_new snd_cx88_source_switch = {
static int snd_cx88_alc_get(struct snd_kcontrol *kcontrol,
			    struct snd_ctl_elem_value *value)
{
	snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
	struct cx88_audio_dev *chip = snd_kcontrol_chip(kcontrol);
	struct cx88_core *core = chip->core;
	s32 val;

@@ -786,7 +791,7 @@ static int snd_cx88_alc_get(struct snd_kcontrol *kcontrol,
static int snd_cx88_alc_put(struct snd_kcontrol *kcontrol,
			    struct snd_ctl_elem_value *value)
{
	snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
	struct cx88_audio_dev *chip = snd_kcontrol_chip(kcontrol);
	struct cx88_core *core = chip->core;

	wm8775_s_ctrl(core, V4L2_CID_AUDIO_LOUDNESS,
@@ -802,9 +807,9 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
	.put = snd_cx88_alc_put,
};

/****************************************************************************
			Basic Flow for Sound Devices
 ****************************************************************************/
/*
 * Basic Flow for Sound Devices
 */

/*
 * PCI ID Table - 14f1:8801 and 14f1:8811 means function 1: Audio
@@ -822,9 +827,8 @@ MODULE_DEVICE_TABLE(pci, cx88_audio_pci_tbl);
 * Chip-specific destructor
 */

static int snd_cx88_free(snd_cx88_card_t *chip)
static int snd_cx88_free(struct cx88_audio_dev *chip)
{

	if (chip->irq >= 0)
		free_irq(chip->irq, chip);

@@ -839,22 +843,21 @@ static int snd_cx88_free(snd_cx88_card_t *chip)
 */
static void snd_cx88_dev_free(struct snd_card *card)
{
	snd_cx88_card_t *chip = card->private_data;
	struct cx88_audio_dev *chip = card->private_data;

	snd_cx88_free(chip);
}


/*
 * Alsa Constructor - Component probe
 */

static int devno;
static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci,
			   snd_cx88_card_t **rchip,
			   struct cx88_audio_dev **rchip,
			   struct cx88_core **core_ptr)
{
	snd_cx88_card_t   *chip;
	struct cx88_audio_dev	*chip;
	struct cx88_core	*core;
	int			err;
	unsigned char		pci_lat;
@@ -870,7 +873,7 @@ static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci,
	chip = card->private_data;

	core = cx88_core_get(pci);
	if (core == NULL) {
	if (!core) {
		err = -EINVAL;
		return err;
	}
@@ -882,7 +885,6 @@ static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci,
		return err;
	}


	/* pci init */
	chip->card = card;
	chip->pci = pci;
@@ -903,7 +905,8 @@ static int snd_cx88_create(struct snd_card *card, struct pci_dev *pci,
	/* print pci info */
	pci_read_config_byte(pci, PCI_LATENCY_TIMER, &pci_lat);

	dprintk(1, "ALSA %s/%i: found at %s, rev: %d, irq: %d, latency: %d, mmio: 0x%llx\n",
	dprintk(1,
		"ALSA %s/%i: found at %s, rev: %d, irq: %d, latency: %d, mmio: 0x%llx\n",
		core->name, devno,
		pci_name(pci), pci->revision, pci->irq,
		pci_lat, (unsigned long long)pci_resource_start(pci, 0));
@@ -921,7 +924,7 @@ static int cx88_audio_initdev(struct pci_dev *pci,
			      const struct pci_device_id *pci_id)
{
	struct snd_card		*card;
	snd_cx88_card_t  *chip;
	struct cx88_audio_dev	*chip;
	struct cx88_core	*core = NULL;
	int			err;

@@ -934,7 +937,7 @@ static int cx88_audio_initdev(struct pci_dev *pci,
	}

	err = snd_card_new(&pci->dev, index[devno], id[devno], THIS_MODULE,
			   sizeof(snd_cx88_card_t), &card);
			   sizeof(struct cx88_audio_dev), &card);
	if (err < 0)
		return err;

@@ -984,6 +987,7 @@ static int cx88_audio_initdev(struct pci_dev *pci,
	snd_card_free(card);
	return err;
}

/*
 * ALSA destructor
 */
+101 −68

File changed.

Preview size limit exceeded, changes collapsed.

+168 −145

File changed.

Preview size limit exceeded, changes collapsed.

+105 −100
Original line number Diff line number Diff line
@@ -72,8 +72,10 @@ static DEFINE_MUTEX(devlist);

#define NO_SYNC_LINE (-1U)

/* @lpi: lines per IRQ, or 0 to not generate irqs. Note: IRQ to be
	 generated _after_ lpi lines are transferred. */
/*
 * @lpi: lines per IRQ, or 0 to not generate irqs. Note: IRQ to be
 * generated _after_ lpi lines are transferred.
 */
static __le32 *cx88_risc_field(__le32 *rp, struct scatterlist *sglist,
			       unsigned int offset, u32 sync_line,
			       unsigned int bpl, unsigned int padding,
@@ -104,7 +106,8 @@ static __le32 *cx88_risc_field(__le32 *rp, struct scatterlist *sglist,
			sol = RISC_SOL;
		if (bpl <= sg_dma_len(sg) - offset) {
			/* fits into current chunk */
			*(rp++) = cpu_to_le32(RISC_WRITE|sol|RISC_EOL|bpl);
			*(rp++) = cpu_to_le32(RISC_WRITE | sol |
					      RISC_EOL | bpl);
			*(rp++) = cpu_to_le32(sg_dma_address(sg) + offset);
			offset += bpl;
		} else {
@@ -147,16 +150,19 @@ int cx88_risc_buffer(struct pci_dev *pci, struct cx88_riscmem *risc,
	if (bottom_offset != UNSET)
		fields++;

	/* estimate risc mem: worst case is one write per page border +
	   one write per scan line + syncs + jump (all 2 dwords).  Padding
	   can cause next bpl to start close to a page border.  First DMA
	   region may be smaller than PAGE_SIZE */
	instructions  = fields * (1 + ((bpl + padding) * lines) / PAGE_SIZE + lines);
	/*
	 * estimate risc mem: worst case is one write per page border +
	 * one write per scan line + syncs + jump (all 2 dwords).  Padding
	 * can cause next bpl to start close to a page border.  First DMA
	 * region may be smaller than PAGE_SIZE
	 */
	instructions  = fields * (1 + ((bpl + padding) * lines) /
				  PAGE_SIZE + lines);
	instructions += 4;
	risc->size = instructions * 8;
	risc->dma = 0;
	risc->cpu = pci_zalloc_consistent(pci, risc->size, &risc->dma);
	if (risc->cpu == NULL)
	if (!risc->cpu)
		return -ENOMEM;

	/* write risc instructions */
@@ -166,13 +172,15 @@ int cx88_risc_buffer(struct pci_dev *pci, struct cx88_riscmem *risc,
				     bpl, padding, lines, 0, true);
	if (bottom_offset != UNSET)
		rp = cx88_risc_field(rp, sglist, bottom_offset, 0x200,
				     bpl, padding, lines, 0, top_offset == UNSET);
				     bpl, padding, lines, 0,
				     top_offset == UNSET);

	/* save pointer to jmp instruction address */
	risc->jmp = rp;
	WARN_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size);
	return 0;
}
EXPORT_SYMBOL(cx88_risc_buffer);

int cx88_risc_databuffer(struct pci_dev *pci, struct cx88_riscmem *risc,
			 struct scatterlist *sglist, unsigned int bpl,
@@ -181,32 +189,38 @@ int cx88_risc_databuffer(struct pci_dev *pci, struct cx88_riscmem *risc,
	u32 instructions;
	__le32 *rp;

	/* estimate risc mem: worst case is one write per page border +
	   one write per scan line + syncs + jump (all 2 dwords).  Here
	   there is no padding and no sync.  First DMA region may be smaller
	   than PAGE_SIZE */
	/*
	 * estimate risc mem: worst case is one write per page border +
	 * one write per scan line + syncs + jump (all 2 dwords).  Here
	 * there is no padding and no sync.  First DMA region may be smaller
	 * than PAGE_SIZE
	 */
	instructions  = 1 + (bpl * lines) / PAGE_SIZE + lines;
	instructions += 3;
	risc->size = instructions * 8;
	risc->dma = 0;
	risc->cpu = pci_zalloc_consistent(pci, risc->size, &risc->dma);
	if (risc->cpu == NULL)
	if (!risc->cpu)
		return -ENOMEM;

	/* write risc instructions */
	rp = risc->cpu;
	rp = cx88_risc_field(rp, sglist, 0, NO_SYNC_LINE, bpl, 0, lines, lpi, !lpi);
	rp = cx88_risc_field(rp, sglist, 0, NO_SYNC_LINE, bpl, 0,
			     lines, lpi, !lpi);

	/* save pointer to jmp instruction address */
	risc->jmp = rp;
	WARN_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size);
	return 0;
}
EXPORT_SYMBOL(cx88_risc_databuffer);

/* ------------------------------------------------------------------ */
/* our SRAM memory layout                                             */
/*
 * our SRAM memory layout
 */

/* we are going to put all thr risc programs into host memory, so we
/*
 * we are going to put all thr risc programs into host memory, so we
 * can use the whole SDRAM for the DMA fifos.  To simplify things, we
 * use a static memory layout.  That surely will waste memory in case
 * we don't use all DMA channels at the same time (which will be the
@@ -330,6 +344,7 @@ const struct sram_channel cx88_sram_channels[] = {
		.cnt2_reg   = MO_DMA27_CNT2,
	},
};
EXPORT_SYMBOL(cx88_sram_channels);

int cx88_sram_channel_setup(struct cx88_core *core,
			    const struct sram_channel *ch,
@@ -367,6 +382,7 @@ int cx88_sram_channel_setup(struct cx88_core *core,
	dprintk(2, "sram setup %s: bpl=%d lines=%d\n", ch->name, bpl, lines);
	return 0;
}
EXPORT_SYMBOL(cx88_sram_channel_setup);

/* ------------------------------------------------------------------ */
/* debug helper code                                                  */
@@ -409,7 +425,6 @@ static int cx88_risc_decode(u32 risc)
	return incr[risc >> 28] ? incr[risc >> 28] : 1;
}


void cx88_sram_channel_dump(struct cx88_core *core,
			    const struct sram_channel *ch)
{
@@ -429,12 +444,10 @@ void cx88_sram_channel_dump(struct cx88_core *core,
	u32 risc;
	unsigned int i, j, n;

	dprintk0("%s - dma channel status dump\n",
		ch->name);
	dprintk0("%s - dma channel status dump\n", ch->name);
	for (i = 0; i < ARRAY_SIZE(name); i++)
		dprintk0("   cmds: %-12s: 0x%08x\n",
			name[i],
			cx_read(ch->cmds_start + 4*i));
			 name[i], cx_read(ch->cmds_start + 4 * i));
	for (n = 1, i = 0; i < 4; i++) {
		risc = cx_read(ch->cmds_start + 4 * (i + 11));
		pr_cont("  risc%d: ", i);
@@ -463,6 +476,7 @@ void cx88_sram_channel_dump(struct cx88_core *core,
	dprintk0("  cnt1_reg: 0x%08x\n", cx_read(ch->cnt1_reg));
	dprintk0("  cnt2_reg: 0x%08x\n", cx_read(ch->cnt2_reg));
}
EXPORT_SYMBOL(cx88_sram_channel_dump);

static const char *cx88_pci_irqs[32] = {
	"vid", "aud", "ts", "vip", "hst", "5", "6", "tm1",
@@ -490,6 +504,7 @@ void cx88_print_irqbits(const char *tag, const char *strings[],
	}
	pr_cont("\n");
}
EXPORT_SYMBOL(cx88_print_irqbits);

/* ------------------------------------------------------------------ */

@@ -507,6 +522,7 @@ int cx88_core_irq(struct cx88_core *core, u32 status)
				   status, core->pci_irqmask);
	return handled;
}
EXPORT_SYMBOL(cx88_core_irq);

void cx88_wakeup(struct cx88_core *core,
		 struct cx88_dmaqueue *q, u32 count)
@@ -521,6 +537,7 @@ void cx88_wakeup(struct cx88_core *core,
	list_del(&buf->list);
	vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
}
EXPORT_SYMBOL(cx88_wakeup);

void cx88_shutdown(struct cx88_core *core)
{
@@ -545,6 +562,7 @@ void cx88_shutdown(struct cx88_core *core)
	/* stop capturing */
	cx_write(VID_CAPTURE_CONTROL, 0);
}
EXPORT_SYMBOL(cx88_shutdown);

int cx88_reset(struct cx88_core *core)
{
@@ -560,13 +578,15 @@ int cx88_reset(struct cx88_core *core)
	msleep(100);

	/* init sram */
	cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21], 720*4, 0);
	cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21],
				720 * 4, 0);
	cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH22], 128, 0);
	cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH23], 128, 0);
	cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH24], 128, 0);
	cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH25], 128, 0);
	cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH26], 128, 0);
	cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH28], 188*4, 0);
	cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH28],
				188 * 4, 0);
	cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH27], 128, 0);

	/* misc init ... */
@@ -594,11 +614,12 @@ int cx88_reset(struct cx88_core *core)

	/* Reset on-board parts */
	cx_write(MO_SRST_IO, 0);
	msleep(10);
	usleep_range(10000, 20000);
	cx_write(MO_SRST_IO, 1);

	return 0;
}
EXPORT_SYMBOL(cx88_reset);

/* ------------------------------------------------------------------ */

@@ -628,10 +649,11 @@ static inline unsigned int norm_fsc8(v4l2_std_id norm)
	if (norm & V4L2_STD_NTSC) // All NTSC/M and variants
		return 28636360;      // 3.57954545 MHz +/- 10 Hz

	/* SECAM have also different sub carrier for chroma,
	   but step_db and step_dr, at cx88_set_tvnorm already handles that.

	   The same FSC applies to PAL/BGDKIH, PAL/60, NTSC/4.43 and PAL/N
	/*
	 * SECAM have also different sub carrier for chroma,
	 * but step_db and step_dr, at cx88_set_tvnorm already handles that.
	 *
	 * The same FSC applies to PAL/BGDKIH, PAL/60, NTSC/4.43 and PAL/N
	 */

	return 35468950;      // 4.43361875 MHz +/- 5 Hz
@@ -639,7 +661,6 @@ static inline unsigned int norm_fsc8(v4l2_std_id norm)

static inline unsigned int norm_htotal(v4l2_std_id norm)
{

	unsigned int fsc4 = norm_fsc8(norm) / 2;

	/* returns 4*FSC / vtotal / frames per seconds */
@@ -653,8 +674,8 @@ static inline unsigned int norm_vbipack(v4l2_std_id norm)
	return (norm & V4L2_STD_625_50) ? 511 : 400;
}

int cx88_set_scale(struct cx88_core *core, unsigned int width, unsigned int height,
		   enum v4l2_field field)
int cx88_set_scale(struct cx88_core *core, unsigned int width,
		   unsigned int height, enum v4l2_field field)
{
	unsigned int swidth  = norm_swidth(core->tvnorm);
	unsigned int sheight = norm_maxh(core->tvnorm);
@@ -721,6 +742,7 @@ int cx88_set_scale(struct cx88_core *core, unsigned int width, unsigned int heig

	return 0;
}
EXPORT_SYMBOL(cx88_set_scale);

static const u32 xtal = 28636363;

@@ -755,7 +777,7 @@ static int set_pll(struct cx88_core *core, int prescale, u32 ofreq)
			return 0;
		}
		dprintk(1, "pll not locked yet, waiting ...\n");
		msleep(10);
		usleep_range(10000, 20000);
	}
	dprintk(1, "pll NOT locked [pre=%d,ofreq=%d]\n", prescale, ofreq);
	return -1;
@@ -803,8 +825,8 @@ static int set_tvaudio(struct cx88_core *core)
{
	v4l2_std_id norm = core->tvnorm;

	if (CX88_VMUX_TELEVISION != INPUT(core->input).type &&
	    CX88_VMUX_CABLE != INPUT(core->input).type)
	if (INPUT(core->input).type != CX88_VMUX_TELEVISION &&
	    INPUT(core->input).type != CX88_VMUX_CABLE)
		return 0;

	if (V4L2_STD_PAL_BG & norm) {
@@ -819,7 +841,8 @@ static int set_tvaudio(struct cx88_core *core)
	} else if (V4L2_STD_SECAM_L & norm) {
		core->tvaudio = WW_L;

	} else if ((V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H) & norm) {
	} else if ((V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H) &
		   norm) {
		core->tvaudio = WW_BG;

	} else if (V4L2_STD_SECAM_DK & norm) {
@@ -844,15 +867,13 @@ static int set_tvaudio(struct cx88_core *core)
	/* cx88_set_stereo(dev,V4L2_TUNER_MODE_STEREO); */

/*
   This should be needed only on cx88-alsa. It seems that some cx88 chips have
   bugs and does require DMA enabled for it to work.
 * This should be needed only on cx88-alsa. It seems that some cx88 chips have
 * bugs and does require DMA enabled for it to work.
 */
	cx88_start_audio_dma(core);
	return 0;
}



int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm)
{
	u32 fsc8;
@@ -916,8 +937,10 @@ int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm)

	dprintk(1, "set_tvnorm: MO_INPUT_FORMAT  0x%08x [old=0x%08x]\n",
		cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f);
	/* Chroma AGC must be disabled if SECAM is used, we enable it
	   by default on PAL and NTSC */
	/*
	 * Chroma AGC must be disabled if SECAM is used, we enable it
	 * by default on PAL and NTSC
	 */
	cx_andor(MO_INPUT_FORMAT, 0x40f,
		 norm & V4L2_STD_SECAM ? cxiformat : cxiformat | 0x400);

@@ -952,7 +975,8 @@ int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm)
	agcdelay = vdec_clock * 68 / 20000000 + 15;
	dprintk(1,
		"set_tvnorm: MO_AGC_BURST     0x%08x [old=0x%08x,bdelay=%d,agcdelay=%d]\n",
		(bdelay << 8) | agcdelay, cx_read(MO_AGC_BURST), bdelay, agcdelay);
		(bdelay << 8) | agcdelay, cx_read(MO_AGC_BURST),
		bdelay, agcdelay);
	cx_write(MO_AGC_BURST, (bdelay << 8) | agcdelay);

	// htotal
@@ -977,12 +1001,16 @@ int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm)
	// tell i2c chips
	call_all(core, video, s_std, norm);

	/* The chroma_agc control should be inaccessible if the video format is SECAM */
	/*
	 * The chroma_agc control should be inaccessible
	 * if the video format is SECAM
	 */
	v4l2_ctrl_grab(core->chroma_agc, cxiformat == VideoFormatSECAM);

	// done
	return 0;
}
EXPORT_SYMBOL(cx88_set_tvnorm);

/* ------------------------------------------------------------------ */

@@ -1007,6 +1035,7 @@ void cx88_vdev_init(struct cx88_core *core,
	snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
		 core->name, type, core->board.name);
}
EXPORT_SYMBOL(cx88_vdev_init);

struct cx88_core *cx88_core_get(struct pci_dev *pci)
{
@@ -1029,7 +1058,7 @@ struct cx88_core *cx88_core_get(struct pci_dev *pci)
	}

	core = cx88_core_create(pci, cx88_devcount);
	if (core != NULL) {
	if (core) {
		cx88_devcount++;
		list_add_tail(&core->devlist, &cx88_devlist);
	}
@@ -1037,6 +1066,7 @@ struct cx88_core *cx88_core_get(struct pci_dev *pci)
	mutex_unlock(&devlist);
	return core;
}
EXPORT_SYMBOL(cx88_core_get);

void cx88_core_put(struct cx88_core *core, struct pci_dev *pci)
{
@@ -1062,29 +1092,4 @@ void cx88_core_put(struct cx88_core *core, struct pci_dev *pci)
	v4l2_device_unregister(&core->v4l2_dev);
	kfree(core);
}

/* ------------------------------------------------------------------ */

EXPORT_SYMBOL(cx88_print_irqbits);

EXPORT_SYMBOL(cx88_core_irq);
EXPORT_SYMBOL(cx88_wakeup);
EXPORT_SYMBOL(cx88_reset);
EXPORT_SYMBOL(cx88_shutdown);

EXPORT_SYMBOL(cx88_risc_buffer);
EXPORT_SYMBOL(cx88_risc_databuffer);

EXPORT_SYMBOL(cx88_sram_channels);
EXPORT_SYMBOL(cx88_sram_channel_setup);
EXPORT_SYMBOL(cx88_sram_channel_dump);

EXPORT_SYMBOL(cx88_set_tvnorm);
EXPORT_SYMBOL(cx88_set_scale);

EXPORT_SYMBOL(cx88_vdev_init);
EXPORT_SYMBOL(cx88_core_get);
EXPORT_SYMBOL(cx88_core_put);

EXPORT_SYMBOL(cx88_ir_start);
EXPORT_SYMBOL(cx88_ir_stop);
+32 −18
Original line number Diff line number Diff line
@@ -31,18 +31,22 @@
#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 the sampling rate of the audio rds fifo. */
/*
 * We calculate the baseband frequencies of the carrier and the pilot tones
 * based on the 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
/*
 * 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... */
 * calculate the proper baseband frequencies...
 */

#define FREQ_A2M_CARRIER	((s32)(2.114516 * 32768.0))
#define FREQ_A2M_DUAL		((s32)(2.754916 * 32768.0))
@@ -83,8 +87,10 @@ static s32 int_cos(u32 x)
	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. */
	/*
	 * 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;
@@ -95,8 +101,10 @@ static s32 int_cos(u32 x)

static u32 int_goertzel(s16 x[], u32 N, u32 freq)
{
	/* We use the Goertzel algorithm to determine the power of the
	 * given frequency in the signal */
	/*
	 * We use the Goertzel algorithm to determine the power of the
	 * given frequency in the signal
	 */
	s32 s_prev = 0;
	s32 s_prev2 = 0;
	s32 coeff = 2 * int_cos(freq);
@@ -115,8 +123,10 @@ static u32 int_goertzel(s16 x[], u32 N, u32 freq)
	tmp = (s64)s_prev2 * s_prev2 + (s64)s_prev * s_prev -
		      (s64)coeff * s_prev2 * s_prev / 32768;

	/* XXX: N must be low enough so that N*N fits in s32.
	 * Else we need two divisions. */
	/*
	 * XXX: N must be low enough so that N*N fits in s32.
	 * Else we need two divisions.
	 */
	divisor = N * N;
	do_div(tmp, divisor);

@@ -187,7 +197,8 @@ static s32 detect_a2_a2m_eiaj(struct cx88_core *core, s16 x[], u32 N)
	dual    = freq_magnitude(x, N, dual_freq);
	noise   = noise_magnitude(x, N, FREQ_NOISE_START, FREQ_NOISE_END);

	dprintk(1, "detect a2/a2m/eiaj: carrier=%d, stereo=%d, dual=%d, noise=%d\n",
	dprintk(1,
		"detect a2/a2m/eiaj: carrier=%d, stereo=%d, dual=%d, noise=%d\n",
		carrier, stereo, dual, noise);

	if (stereo > dual)
@@ -201,8 +212,10 @@ static s32 detect_a2_a2m_eiaj(struct cx88_core *core, s16 x[], u32 N)
		    (carrier < max(stereo, dual) * 6) &&
		    (carrier > 20 && carrier < 200) &&
		    (max(stereo, dual) > min(stereo, dual))) {
			/* For EIAJ the carrier is always present,
			   so we probably don't need noise detection */
			/*
			 * For EIAJ the carrier is always present,
			 * so we probably don't need noise detection
			 */
			return ret;
		}
	} else {
@@ -243,7 +256,8 @@ static s16 *read_rds_samples(struct cx88_core *core, u32 *N)
	u32 current_address = cx_read(srch->ptr1_reg);
	u32 offset = (current_address - srch->fifo_start + bpl);

	dprintk(1, "read RDS samples: current_address=%08x (offset=%08x), sample_count=%d, aud_intstat=%08x\n",
	dprintk(1,
		"read RDS samples: current_address=%08x (offset=%08x), sample_count=%d, aud_intstat=%08x\n",
		current_address,
		current_address - srch->fifo_start, sample_count,
		cx_read(MO_AUD_INTSTAT));
Loading