Skip to content

Commit

Permalink
V4L/DVB (8462): cx18: Lock the aux PLL to the video pixle rate for an…
Browse files Browse the repository at this point in the history
…alog captures

cx18: Lock the aux PLL to the video pixel rate for analog captures.  The
datasheet for the CX25840 says this is important for MPEG encoding applications.
To ensure the PLL locking was correct, also fixed the aux PLL's multiplier to
be computed based on a precise crystal freq of 4.5 MHz/286 * 455/2 * 8 =
28636363.6363... instead of the imporperly rounded 28636363.

Signed-off-by: Andy Walls <awalls@radix.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
  • Loading branch information
Andy Walls authored and Mauro Carvalho Chehab committed Jul 26, 2008
1 parent f8f6296 commit 35f92b2
Showing 1 changed file with 70 additions and 10 deletions.
80 changes: 70 additions & 10 deletions drivers/media/video/cx18/cx18-av-audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,66 @@ static int set_audclk_freq(struct cx18 *cx, u32 freq)

/* SA_MCLK_SEL=1, SA_MCLK_DIV=0x14 */
cx18_av_write(cx, 0x127, 0x54);

/* AUD_COUNT = 0x2fff = 8 samples * 4 * 384 - 1 */
cx18_av_write4(cx, 0x12c, 0x11202fff);

/*
* EN_AV_LOCK = 1
* VID_COUNT = 0x0d2ef8 = 107999.000 * 8 =
* ((8 samples/32,000) * (13,500,000 * 8) * 4 - 1) * 8
*/
cx18_av_write4(cx, 0x128, 0xa10d2ef8);
break;

case 44100:
/* VID_PLL and AUX_PLL */
cx18_av_write4(cx, 0x108, 0x1009040f);

/* AUX_PLL_FRAC */
/* 0x9.7635eb * 28,636,363 / 0x10 = 44100 * 384 */
cx18_av_write4(cx, 0x110, 0x00ec6bd6);
/* 0x9.7635e7 * 28,636,363.63 / 0x10 = 44100 * 384 */
cx18_av_write4(cx, 0x110, 0x00ec6bce);

/* src3/4/6_ctl */
/* 0x1.6d59 = (4 * 15734.26) / 44100 */
cx18_av_write4(cx, 0x900, 0x08016d59);
cx18_av_write4(cx, 0x904, 0x08016d59);
cx18_av_write4(cx, 0x90c, 0x08016d59);

/* AUD_COUNT = 0x92ff = 49 samples * 2 * 384 - 1 */
cx18_av_write4(cx, 0x12c, 0x112092ff);

/*
* EN_AV_LOCK = 1
* VID_COUNT = 0x1d4bf8 = 239999.000 * 8 =
* ((49 samples/44,100) * (13,500,000 * 8) * 2 - 1) * 8
*/
cx18_av_write4(cx, 0x128, 0xa11d4bf8);
break;

case 48000:
/* VID_PLL and AUX_PLL */
cx18_av_write4(cx, 0x108, 0x100a040f);

/* AUX_PLL_FRAC */
/* 0xa.4c6b728 * 28,636,363 / 0x10 = 48000 * 384 */
cx18_av_write4(cx, 0x110, 0x0098d6e5);
/* 0xa.4c6b6ea * 28,636,363.63 / 0x10 = 48000 * 384 */
cx18_av_write4(cx, 0x110, 0x0098d6dd);

/* src3/4/6_ctl */
/* 0x1.4faa = (4 * 15734.26) / 48000 */
cx18_av_write4(cx, 0x900, 0x08014faa);
cx18_av_write4(cx, 0x904, 0x08014faa);
cx18_av_write4(cx, 0x90c, 0x08014faa);

/* AUD_COUNT = 0x5fff = 4 samples * 16 * 384 - 1 */
cx18_av_write4(cx, 0x12c, 0x11205fff);

/*
* EN_AV_LOCK = 1
* VID_COUNT = 0x1193f8 = 143999.000 * 8 =
* ((4 samples/48,000) * (13,500,000 * 8) * 16 - 1) * 8
*/
cx18_av_write4(cx, 0x128, 0xa11193f8);
break;
}
} else {
Expand All @@ -90,8 +120,8 @@ static int set_audclk_freq(struct cx18 *cx, u32 freq)
cx18_av_write4(cx, 0x108, 0x1e08040f);

/* AUX_PLL_FRAC */
/* 0x8.9504348 * 28,636,363 / 0x1e = 32000 * 256 */
cx18_av_write4(cx, 0x110, 0x012a0869);
/* 0x8.9504318 * 28,636,363.63 / 0x1e = 32000 * 256 */
cx18_av_write4(cx, 0x110, 0x012a0863);

/* src1_ctl */
/* 0x1.0000 = 32000/32000 */
Expand All @@ -105,15 +135,25 @@ static int set_audclk_freq(struct cx18 *cx, u32 freq)

/* SA_MCLK_SEL=1, SA_MCLK_DIV=0x14 */
cx18_av_write(cx, 0x127, 0x54);

/* AUD_COUNT = 0x1fff = 8 samples * 4 * 256 - 1 */
cx18_av_write4(cx, 0x12c, 0x11201fff);

/*
* EN_AV_LOCK = 1
* VID_COUNT = 0x0d2ef8 = 107999.000 * 8 =
* ((8 samples/32,000) * (13,500,000 * 8) * 4 - 1) * 8
*/
cx18_av_write4(cx, 0x128, 0xa10d2ef8);
break;

case 44100:
/* VID_PLL and AUX_PLL */
cx18_av_write4(cx, 0x108, 0x1809040f);

/* AUX_PLL_FRAC */
/* 0x9.76346B * 28,636,363 / 0x18 = 44100 * 256 */
cx18_av_write4(cx, 0x110, 0x00ec6bd6);
/* 0x9.7635e74 * 28,636,363.63 / 0x18 = 44100 * 256 */
cx18_av_write4(cx, 0x110, 0x00ec6bce);

/* src1_ctl */
/* 0x1.60cd = 44100/32000 */
Expand All @@ -124,15 +164,25 @@ static int set_audclk_freq(struct cx18 *cx, u32 freq)
cx18_av_write4(cx, 0x900, 0x08017385);
cx18_av_write4(cx, 0x904, 0x08017385);
cx18_av_write4(cx, 0x90c, 0x08017385);

/* AUD_COUNT = 0x61ff = 49 samples * 2 * 256 - 1 */
cx18_av_write4(cx, 0x12c, 0x112061ff);

/*
* EN_AV_LOCK = 1
* VID_COUNT = 0x1d4bf8 = 239999.000 * 8 =
* ((49 samples/44,100) * (13,500,000 * 8) * 2 - 1) * 8
*/
cx18_av_write4(cx, 0x128, 0xa11d4bf8);
break;

case 48000:
/* VID_PLL and AUX_PLL */
cx18_av_write4(cx, 0x108, 0x180a040f);

/* AUX_PLL_FRAC */
/* 0xa.4c6b728 * 28,636,363 / 0x18 = 48000 * 256 */
cx18_av_write4(cx, 0x110, 0x0098d6e5);
/* 0xa.4c6b6ea * 28,636,363.63 / 0x18 = 48000 * 256 */
cx18_av_write4(cx, 0x110, 0x0098d6dd);

/* src1_ctl */
/* 0x1.8000 = 48000/32000 */
Expand All @@ -143,6 +193,16 @@ static int set_audclk_freq(struct cx18 *cx, u32 freq)
cx18_av_write4(cx, 0x900, 0x08015555);
cx18_av_write4(cx, 0x904, 0x08015555);
cx18_av_write4(cx, 0x90c, 0x08015555);

/* AUD_COUNT = 0x3fff = 4 samples * 16 * 256 - 1 */
cx18_av_write4(cx, 0x12c, 0x11203fff);

/*
* EN_AV_LOCK = 1
* VID_COUNT = 0x1193f8 = 143999.000 * 8 =
* ((4 samples/48,000) * (13,500,000 * 8) * 16 - 1) * 8
*/
cx18_av_write4(cx, 0x128, 0xa11193f8);
break;
}
}
Expand Down

0 comments on commit 35f92b2

Please sign in to comment.