Commit 149783b5 authored by Sri Deevi's avatar Sri Deevi Committed by Mauro Carvalho Chehab

V4L/DVB (10952): cx25840: prepare it to be used by cx231xx module

cx231xx has a cx25840 inside the chip. However, some different
initializations are used for this variant.
Signed-off-by: default avatarSrinivasa Deevi <srinivasa.deevi@conexant.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 073d696d
...@@ -32,7 +32,7 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) ...@@ -32,7 +32,7 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
/* common for all inputs and rates */ /* common for all inputs and rates */
/* SA_MCLK_SEL=1, SA_MCLK_DIV=0x10 */ /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x10 */
if (!state->is_cx23885) if (!state->is_cx23885 && !state->is_cx231xx)
cx25840_write(client, 0x127, 0x50); cx25840_write(client, 0x127, 0x50);
if (state->aud_input != CX25840_AUDIO_SERIAL) { if (state->aud_input != CX25840_AUDIO_SERIAL) {
...@@ -43,11 +43,15 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) ...@@ -43,11 +43,15 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
* so avoid destroying registers. */ * so avoid destroying registers. */
break; break;
} }
if (!state->is_cx231xx) {
/* VID_PLL and AUX_PLL */ /* VID_PLL and AUX_PLL */
cx25840_write4(client, 0x108, 0x1006040f); cx25840_write4(client, 0x108, 0x1006040f);
/* AUX_PLL_FRAC */ /* AUX_PLL_FRAC */
cx25840_write4(client, 0x110, 0x01bb39ee); cx25840_write4(client, 0x110, 0x01bb39ee);
}
if (state->is_cx25836) if (state->is_cx25836)
break; break;
...@@ -64,11 +68,15 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) ...@@ -64,11 +68,15 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
* so avoid destroying registers. */ * so avoid destroying registers. */
break; break;
} }
if (!state->is_cx231xx) {
/* VID_PLL and AUX_PLL */ /* VID_PLL and AUX_PLL */
cx25840_write4(client, 0x108, 0x1009040f); cx25840_write4(client, 0x108, 0x1009040f);
/* AUX_PLL_FRAC */ /* AUX_PLL_FRAC */
cx25840_write4(client, 0x110, 0x00ec6bd6); cx25840_write4(client, 0x110, 0x00ec6bd6);
}
if (state->is_cx25836) if (state->is_cx25836)
break; break;
...@@ -85,11 +93,15 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) ...@@ -85,11 +93,15 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
* so avoid destroying registers. */ * so avoid destroying registers. */
break; break;
} }
if (!state->is_cx231xx) {
/* VID_PLL and AUX_PLL */ /* VID_PLL and AUX_PLL */
cx25840_write4(client, 0x108, 0x100a040f); cx25840_write4(client, 0x108, 0x100a040f);
/* AUX_PLL_FRAC */ /* AUX_PLL_FRAC */
cx25840_write4(client, 0x110, 0x0098d6e5); cx25840_write4(client, 0x110, 0x0098d6e5);
}
if (state->is_cx25836) if (state->is_cx25836)
break; break;
...@@ -108,11 +120,15 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) ...@@ -108,11 +120,15 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
* so avoid destroying registers. */ * so avoid destroying registers. */
break; break;
} }
if (!state->is_cx231xx) {
/* VID_PLL and AUX_PLL */ /* VID_PLL and AUX_PLL */
cx25840_write4(client, 0x108, 0x1e08040f); cx25840_write4(client, 0x108, 0x1e08040f);
/* AUX_PLL_FRAC */ /* AUX_PLL_FRAC */
cx25840_write4(client, 0x110, 0x012a0869); cx25840_write4(client, 0x110, 0x012a0869);
}
if (state->is_cx25836) if (state->is_cx25836)
break; break;
...@@ -136,11 +152,15 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) ...@@ -136,11 +152,15 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
break; break;
} }
if (!state->is_cx231xx) {
/* VID_PLL and AUX_PLL */ /* VID_PLL and AUX_PLL */
cx25840_write4(client, 0x108, 0x1809040f); cx25840_write4(client, 0x108, 0x1809040f);
/* AUX_PLL_FRAC */ /* AUX_PLL_FRAC */
cx25840_write4(client, 0x110, 0x00ec6bd6); cx25840_write4(client, 0x110, 0x00ec6bd6);
}
if (state->is_cx25836) if (state->is_cx25836)
break; break;
...@@ -155,7 +175,7 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) ...@@ -155,7 +175,7 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
break; break;
case 48000: case 48000:
if (!state->is_cx23885) { if (!state->is_cx23885 && !state->is_cx231xx) {
/* VID_PLL and AUX_PLL */ /* VID_PLL and AUX_PLL */
cx25840_write4(client, 0x108, 0x180a040f); cx25840_write4(client, 0x108, 0x180a040f);
...@@ -166,7 +186,7 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) ...@@ -166,7 +186,7 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
if (state->is_cx25836) if (state->is_cx25836)
break; break;
if (!state->is_cx23885) { if (!state->is_cx23885 && !state->is_cx231xx) {
/* src1_ctl */ /* src1_ctl */
cx25840_write4(client, 0x8f8, 0x08018000); cx25840_write4(client, 0x8f8, 0x08018000);
...@@ -227,7 +247,7 @@ void cx25840_audio_set_path(struct i2c_client *client) ...@@ -227,7 +247,7 @@ void cx25840_audio_set_path(struct i2c_client *client)
/* deassert soft reset */ /* deassert soft reset */
cx25840_and_or(client, 0x810, ~0x1, 0x00); cx25840_and_or(client, 0x810, ~0x1, 0x00);
if (state->is_cx23885) { if (state->is_cx23885 || state->is_cx231xx) {
/* Ensure the controller is running when we exit */ /* Ensure the controller is running when we exit */
cx25840_and_or(client, 0x803, ~0x10, 0x10); cx25840_and_or(client, 0x803, ~0x10, 0x10);
} }
......
...@@ -345,6 +345,81 @@ static void cx23885_initialize(struct i2c_client *client) ...@@ -345,6 +345,81 @@ static void cx23885_initialize(struct i2c_client *client)
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static void cx231xx_initialize(struct i2c_client *client)
{
DEFINE_WAIT(wait);
struct cx25840_state *state = to_state(i2c_get_clientdata(client));
struct workqueue_struct *q;
/* Internal Reset */
cx25840_and_or(client, 0x102, ~0x01, 0x01);
cx25840_and_or(client, 0x102, ~0x01, 0x00);
/* Stop microcontroller */
cx25840_and_or(client, 0x803, ~0x10, 0x00);
/* DIF in reset? */
cx25840_write(client, 0x398, 0);
/* Trust the default xtal, no division */
/* This changes for the cx23888 products */
cx25840_write(client, 0x2, 0x76);
/* Bring down the regulator for AUX clk */
cx25840_write(client, 0x1, 0x40);
/* Disable DIF bypass */
cx25840_write4(client, 0x33c, 0x00000001);
/* DIF Src phase inc */
cx25840_write4(client, 0x340, 0x0df7df83);
/* Luma */
cx25840_write4(client, 0x414, 0x00107d12);
/* Chroma */
cx25840_write4(client, 0x420, 0x3d008282);
/* ADC2 input select */
cx25840_write(client, 0x102, 0x10);
/* VIN1 & VIN5 */
cx25840_write(client, 0x103, 0x11);
/* Enable format auto detect */
cx25840_write(client, 0x400, 0);
/* Fast subchroma lock */
/* White crush, Chroma AGC & Chroma Killer enabled */
cx25840_write(client, 0x401, 0xe8);
/* Do the firmware load in a work handler to prevent.
Otherwise the kernel is blocked waiting for the
bit-banging i2c interface to finish uploading the
firmware. */
INIT_WORK(&state->fw_work, cx25840_work_handler);
init_waitqueue_head(&state->fw_wait);
q = create_singlethread_workqueue("cx25840_fw");
prepare_to_wait(&state->fw_wait, &wait, TASK_UNINTERRUPTIBLE);
queue_work(q, &state->fw_work);
schedule();
finish_wait(&state->fw_wait, &wait);
destroy_workqueue(q);
cx25840_std_setup(client);
/* (re)set input */
set_input(client, state->vid_input, state->aud_input);
/* start microcontroller */
cx25840_and_or(client, 0x803, ~0x10, 0x10);
}
/* ----------------------------------------------------------------------- */
void cx25840_std_setup(struct i2c_client *client) void cx25840_std_setup(struct i2c_client *client)
{ {
struct cx25840_state *state = to_state(i2c_get_clientdata(client)); struct cx25840_state *state = to_state(i2c_get_clientdata(client));
...@@ -414,6 +489,7 @@ void cx25840_std_setup(struct i2c_client *client) ...@@ -414,6 +489,7 @@ void cx25840_std_setup(struct i2c_client *client)
} }
/* DEBUG: Displays configured PLL frequency */ /* DEBUG: Displays configured PLL frequency */
if (!state->is_cx231xx) {
pll_int = cx25840_read(client, 0x108); pll_int = cx25840_read(client, 0x108);
pll_frac = cx25840_read4(client, 0x10c) & 0x1ffffff; pll_frac = cx25840_read4(client, 0x10c) & 0x1ffffff;
pll_post = cx25840_read(client, 0x109); pll_post = cx25840_read(client, 0x109);
...@@ -448,6 +524,7 @@ void cx25840_std_setup(struct i2c_client *client) ...@@ -448,6 +524,7 @@ void cx25840_std_setup(struct i2c_client *client)
hblank, hactive, vblank, vactive, vblank656, hblank, hactive, vblank, vactive, vblank656,
src_decimation, burst, luma_lpf, uv_lpf, comb, sc); src_decimation, burst, luma_lpf, uv_lpf, comb, sc);
} }
}
/* Sets horizontal blanking delay and active lines */ /* Sets horizontal blanking delay and active lines */
cx25840_write(client, 0x470, hblank); cx25840_write(client, 0x470, hblank);
...@@ -596,7 +673,7 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp ...@@ -596,7 +673,7 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp
* configuration in reg (for the cx23885) so we have no * configuration in reg (for the cx23885) so we have no
* need to attempt to flip bits for earlier av decoders. * need to attempt to flip bits for earlier av decoders.
*/ */
if (!state->is_cx23885) { if (!state->is_cx23885 && !state->is_cx231xx) {
switch (aud_input) { switch (aud_input) {
case CX25840_AUDIO_SERIAL: case CX25840_AUDIO_SERIAL:
/* do nothing, use serial audio input */ /* do nothing, use serial audio input */
...@@ -619,7 +696,7 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp ...@@ -619,7 +696,7 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp
/* Set INPUT_MODE to Composite (0) or S-Video (1) */ /* Set INPUT_MODE to Composite (0) or S-Video (1) */
cx25840_and_or(client, 0x401, ~0x6, is_composite ? 0 : 0x02); cx25840_and_or(client, 0x401, ~0x6, is_composite ? 0 : 0x02);
if (!state->is_cx23885) { if (!state->is_cx23885 && !state->is_cx231xx) {
/* Set CH_SEL_ADC2 to 1 if input comes from CH3 */ /* Set CH_SEL_ADC2 to 1 if input comes from CH3 */
cx25840_and_or(client, 0x102, ~0x2, (reg & 0x80) == 0 ? 2 : 0); cx25840_and_or(client, 0x102, ~0x2, (reg & 0x80) == 0 ? 2 : 0);
/* Set DUAL_MODE_ADC2 to 1 if input comes from both CH2&CH3 */ /* Set DUAL_MODE_ADC2 to 1 if input comes from both CH2&CH3 */
...@@ -653,6 +730,19 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp ...@@ -653,6 +730,19 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp
/* I2S_IN_CTL: I2S_IN_SONY_MODE, LEFT SAMPLE on WS=1 */ /* I2S_IN_CTL: I2S_IN_SONY_MODE, LEFT SAMPLE on WS=1 */
cx25840_write(client, 0x914, 0xa0); cx25840_write(client, 0x914, 0xa0);
/* I2S_OUT_CTL:
* I2S_IN_SONY_MODE, LEFT SAMPLE on WS=1
* I2S_OUT_MASTER_MODE = Master
*/
cx25840_write(client, 0x918, 0xa0);
cx25840_write(client, 0x919, 0x01);
} else if (state->is_cx231xx) {
/* Audio channel 1 src : Parallel 1 */
cx25840_write(client, 0x124, 0x03);
/* I2S_IN_CTL: I2S_IN_SONY_MODE, LEFT SAMPLE on WS=1 */
cx25840_write(client, 0x914, 0xa0);
/* I2S_OUT_CTL: /* I2S_OUT_CTL:
* I2S_IN_SONY_MODE, LEFT SAMPLE on WS=1 * I2S_IN_SONY_MODE, LEFT SAMPLE on WS=1
* I2S_OUT_MASTER_MODE = Master * I2S_OUT_MASTER_MODE = Master
...@@ -1118,6 +1208,8 @@ static int cx25840_init(struct v4l2_subdev *sd, u32 val) ...@@ -1118,6 +1208,8 @@ static int cx25840_init(struct v4l2_subdev *sd, u32 val)
cx25836_initialize(client); cx25836_initialize(client);
else if (state->is_cx23885) else if (state->is_cx23885)
cx23885_initialize(client); cx23885_initialize(client);
else if (state->is_cx231xx)
cx231xx_initialize(client);
else else
cx25840_initialize(client); cx25840_initialize(client);
} }
...@@ -1159,7 +1251,7 @@ static int cx25840_s_stream(struct v4l2_subdev *sd, int enable) ...@@ -1159,7 +1251,7 @@ static int cx25840_s_stream(struct v4l2_subdev *sd, int enable)
v4l_dbg(1, cx25840_debug, client, "%s output\n", v4l_dbg(1, cx25840_debug, client, "%s output\n",
enable ? "enable" : "disable"); enable ? "enable" : "disable");
if (enable) { if (enable) {
if (state->is_cx23885) { if (state->is_cx23885 || state->is_cx231xx) {
u8 v = (cx25840_read(client, 0x421) | 0x0b); u8 v = (cx25840_read(client, 0x421) | 0x0b);
cx25840_write(client, 0x421, v); cx25840_write(client, 0x421, v);
} else { } else {
...@@ -1169,7 +1261,7 @@ static int cx25840_s_stream(struct v4l2_subdev *sd, int enable) ...@@ -1169,7 +1261,7 @@ static int cx25840_s_stream(struct v4l2_subdev *sd, int enable)
state->is_cx25836 ? 0x04 : 0x07); state->is_cx25836 ? 0x04 : 0x07);
} }
} else { } else {
if (state->is_cx23885) { if (state->is_cx23885 || state->is_cx231xx) {
u8 v = cx25840_read(client, 0x421) & ~(0x0b); u8 v = cx25840_read(client, 0x421) & ~(0x0b);
cx25840_write(client, 0x421, v); cx25840_write(client, 0x421, v);
} else { } else {
...@@ -1350,6 +1442,8 @@ static int cx25840_reset(struct v4l2_subdev *sd, u32 val) ...@@ -1350,6 +1442,8 @@ static int cx25840_reset(struct v4l2_subdev *sd, u32 val)
cx25836_initialize(client); cx25836_initialize(client);
else if (state->is_cx23885) else if (state->is_cx23885)
cx23885_initialize(client); cx23885_initialize(client);
else if (state->is_cx231xx)
cx231xx_initialize(client);
else else
cx25840_initialize(client); cx25840_initialize(client);
return 0; return 0;
...@@ -1445,10 +1539,12 @@ static int cx25840_probe(struct i2c_client *client, ...@@ -1445,10 +1539,12 @@ static int cx25840_probe(struct i2c_client *client,
} }
else if ((device_id & 0xff00) == 0x8400) { else if ((device_id & 0xff00) == 0x8400) {
id = V4L2_IDENT_CX25840 + ((device_id >> 4) & 0xf); id = V4L2_IDENT_CX25840 + ((device_id >> 4) & 0xf);
} else if (device_id == 0x0000) { } /* else if (device_id == 0x0000) {
id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6; id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6;
} else if (device_id == 0x1313) { } */ else if (device_id == 0x1313) {
id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6; id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6;
} else if ((device_id & 0xfff0) == 0x5A30) {
id = V4L2_IDENT_CX25840 + ((device_id >> 4) & 0xf);
} }
else { else {
v4l_dbg(1, cx25840_debug, client, "cx25840 not found\n"); v4l_dbg(1, cx25840_debug, client, "cx25840 not found\n");
...@@ -1471,6 +1567,7 @@ static int cx25840_probe(struct i2c_client *client, ...@@ -1471,6 +1567,7 @@ static int cx25840_probe(struct i2c_client *client,
state->c = client; state->c = client;
state->is_cx25836 = ((device_id & 0xff00) == 0x8300); state->is_cx25836 = ((device_id & 0xff00) == 0x8300);
state->is_cx23885 = (device_id == 0x0000) || (device_id == 0x1313); state->is_cx23885 = (device_id == 0x0000) || (device_id == 0x1313);
state->is_cx231xx = (device_id == 0x5A3E);
state->vid_input = CX25840_COMPOSITE7; state->vid_input = CX25840_COMPOSITE7;
state->aud_input = CX25840_AUDIO8; state->aud_input = CX25840_AUDIO8;
state->audclk_freq = 48000; state->audclk_freq = 48000;
......
...@@ -50,6 +50,7 @@ struct cx25840_state { ...@@ -50,6 +50,7 @@ struct cx25840_state {
u32 rev; u32 rev;
int is_cx25836; int is_cx25836;
int is_cx23885; int is_cx23885;
int is_cx231xx;
int is_initialized; int is_initialized;
wait_queue_head_t fw_wait; /* wake up when the fw load is finished */ wait_queue_head_t fw_wait; /* wake up when the fw load is finished */
struct work_struct fw_work; /* work entry for fw load */ struct work_struct fw_work; /* work entry for fw load */
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#define FWFILE "v4l-cx25840.fw" #define FWFILE "v4l-cx25840.fw"
#define FWFILE_CX23885 "v4l-cx23885-avcore-01.fw" #define FWFILE_CX23885 "v4l-cx23885-avcore-01.fw"
#define FWFILE_CX231XX "v4l-cx231xx-avcore-01.fw"
/* /*
* Mike Isely <isely@pobox.com> - The FWSEND parameter controls the * Mike Isely <isely@pobox.com> - The FWSEND parameter controls the
...@@ -96,9 +97,17 @@ int cx25840_loadfw(struct i2c_client *client) ...@@ -96,9 +97,17 @@ int cx25840_loadfw(struct i2c_client *client)
u8 buffer[FWSEND]; u8 buffer[FWSEND];
const u8 *ptr; const u8 *ptr;
int size, retval; int size, retval;
int MAX_BUF_SIZE = FWSEND;
if (state->is_cx23885) if (state->is_cx23885)
firmware = FWFILE_CX23885; firmware = FWFILE_CX23885;
else if ( state->is_cx231xx)
firmware = FWFILE_CX231XX;
if( (state->is_cx231xx) && MAX_BUF_SIZE > 16) {
printk(" Firmware download size changed to 16 bytes max length\n");
MAX_BUF_SIZE = 16; /* cx231xx cannot accept more than 16 bytes at a time */
}
if (request_firmware(&fw, firmware, FWDEV(client)) != 0) { if (request_firmware(&fw, firmware, FWDEV(client)) != 0) {
v4l_err(client, "unable to open firmware %s\n", firmware); v4l_err(client, "unable to open firmware %s\n", firmware);
...@@ -113,7 +122,7 @@ int cx25840_loadfw(struct i2c_client *client) ...@@ -113,7 +122,7 @@ int cx25840_loadfw(struct i2c_client *client)
size = fw->size; size = fw->size;
ptr = fw->data; ptr = fw->data;
while (size > 0) { while (size > 0) {
int len = min(FWSEND - 2, size); int len = min(MAX_BUF_SIZE - 2, size);
memcpy(buffer + 2, ptr, len); memcpy(buffer + 2, ptr, len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment