linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / media / video / cx25840 / cx25840-audio.c
index f897c1e..cb9a798 100644 (file)
 
 #include <linux/videodev2.h>
 #include <linux/i2c.h>
+#include <media/audiochip.h>
 #include <media/v4l2-common.h>
-#include <media/cx25840.h>
 
-#include "cx25840-core.h"
+#include "cx25840.h"
 
 static int set_audclk_freq(struct i2c_client *client, u32 freq)
 {
@@ -30,6 +30,9 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
        if (freq != 32000 && freq != 44100 && freq != 48000)
                return -EINVAL;
 
+       /* assert soft reset */
+       cx25840_and_or(client, 0x810, ~0x1, 0x01);
+
        /* common for all inputs and rates */
        /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x10 */
        cx25840_write(client, 0x127, 0x50);
@@ -43,9 +46,6 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
                        /* AUX_PLL_FRAC */
                        cx25840_write4(client, 0x110, 0xee39bb01);
 
-                       if (state->is_cx25836)
-                               break;
-
                        /* src3/4/6_ctl = 0x0801f77f */
                        cx25840_write4(client, 0x900, 0x7ff70108);
                        cx25840_write4(client, 0x904, 0x7ff70108);
@@ -59,9 +59,6 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
                        /* AUX_PLL_FRAC */
                        cx25840_write4(client, 0x110, 0xd66bec00);
 
-                       if (state->is_cx25836)
-                               break;
-
                        /* src3/4/6_ctl = 0x08016d59 */
                        cx25840_write4(client, 0x900, 0x596d0108);
                        cx25840_write4(client, 0x904, 0x596d0108);
@@ -75,9 +72,6 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
                        /* AUX_PLL_FRAC */
                        cx25840_write4(client, 0x110, 0xe5d69800);
 
-                       if (state->is_cx25836)
-                               break;
-
                        /* src3/4/6_ctl = 0x08014faa */
                        cx25840_write4(client, 0x900, 0xaa4f0108);
                        cx25840_write4(client, 0x904, 0xaa4f0108);
@@ -93,9 +87,6 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
                        /* AUX_PLL_FRAC */
                        cx25840_write4(client, 0x110, 0x69082a01);
 
-                       if (state->is_cx25836)
-                               break;
-
                        /* src1_ctl = 0x08010000 */
                        cx25840_write4(client, 0x8f8, 0x00000108);
 
@@ -115,9 +106,6 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
                        /* AUX_PLL_FRAC */
                        cx25840_write4(client, 0x110, 0xd66bec00);
 
-                       if (state->is_cx25836)
-                               break;
-
                        /* src1_ctl = 0x08010000 */
                        cx25840_write4(client, 0x8f8, 0xcd600108);
 
@@ -134,9 +122,6 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
                        /* AUX_PLL_FRAC */
                        cx25840_write4(client, 0x110, 0xe5d69800);
 
-                       if (state->is_cx25836)
-                               break;
-
                        /* src1_ctl = 0x08010000 */
                        cx25840_write4(client, 0x8f8, 0x00800108);
 
@@ -148,6 +133,9 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq)
                }
        }
 
+       /* deassert soft reset */
+       cx25840_and_or(client, 0x810, ~0x1, 0x00);
+
        state->audclk_freq = freq;
 
        return 0;
@@ -160,10 +148,6 @@ void cx25840_audio_set_path(struct i2c_client *client)
        /* stop microcontroller */
        cx25840_and_or(client, 0x803, ~0x10, 0);
 
-       /* assert soft reset */
-       if (!state->is_cx25836)
-               cx25840_and_or(client, 0x810, ~0x1, 0x01);
-
        /* Mute everything to prevent the PFFT! */
        cx25840_write(client, 0x8d3, 0x1f);
 
@@ -177,19 +161,13 @@ void cx25840_audio_set_path(struct i2c_client *client)
        } else {
                /* Set Path1 to Analog Demod Main Channel */
                cx25840_write4(client, 0x8d0, 0x7038061f);
-       }
 
-       set_audclk_freq(client, state->audclk_freq);
-
-       /* deassert soft reset */
-       if (!state->is_cx25836)
-               cx25840_and_or(client, 0x810, ~0x1, 0x00);
-
-       if (state->aud_input != CX25840_AUDIO_SERIAL) {
                /* When the microcontroller detects the
                 * audio format, it will unmute the lines */
                cx25840_and_or(client, 0x803, ~0x10, 0x10);
        }
+
+       set_audclk_freq(client, state->audclk_freq);
 }
 
 static int get_volume(struct i2c_client *client)
@@ -313,25 +291,11 @@ static void set_mute(struct i2c_client *client, int mute)
 
 int cx25840_audio(struct i2c_client *client, unsigned int cmd, void *arg)
 {
-       struct cx25840_state *state = i2c_get_clientdata(client);
        struct v4l2_control *ctrl = arg;
-       int retval;
 
        switch (cmd) {
        case VIDIOC_INT_AUDIO_CLOCK_FREQ:
-               if (state->aud_input != CX25840_AUDIO_SERIAL) {
-                       cx25840_and_or(client, 0x803, ~0x10, 0);
-                       cx25840_write(client, 0x8d3, 0x1f);
-               }
-               if (!state->is_cx25836)
-                       cx25840_and_or(client, 0x810, ~0x1, 1);
-               retval = set_audclk_freq(client, *(u32 *)arg);
-               if (!state->is_cx25836)
-                       cx25840_and_or(client, 0x810, ~0x1, 0);
-               if (state->aud_input != CX25840_AUDIO_SERIAL) {
-                       cx25840_and_or(client, 0x803, ~0x10, 0x10);
-               }
-               return retval;
+               return set_audclk_freq(client, *(u32 *)arg);
 
        case VIDIOC_G_CTRL:
                switch (ctrl->id) {