static int cx25840_audio_s_ctrl(struct v4l2_ctrl *ctrl) { struct v4l2_subdev *sd = to_sd(ctrl); struct cx25840_state *state = to_state(sd); struct i2c_client *client = v4l2_get_subdevdata(sd); switch (ctrl->id) { case V4L2_CID_AUDIO_VOLUME: if (state->mute->val) set_volume(client, 0); else set_volume(client, state->volume->val); break; case V4L2_CID_AUDIO_BASS: /* PATH1_EQ_BASS_VOL */ cx25840_and_or(client, 0x8d9, ~0x3f, 48 - (ctrl->val * 48 / 0xffff)); break; case V4L2_CID_AUDIO_TREBLE: /* PATH1_EQ_TREBLE_VOL */ cx25840_and_or(client, 0x8db, ~0x3f, 48 - (ctrl->val * 48 / 0xffff)); break; case V4L2_CID_AUDIO_BALANCE: set_balance(client, ctrl->val); break; default: return -EINVAL; } return 0; }
void cx25840_audio_set_path(struct i2c_client *client) { struct cx25840_state *state = i2c_get_clientdata(client); /* stop microcontroller */ cx25840_and_or(client, 0x803, ~0x10, 0); /* Mute everything to prevent the PFFT! */ cx25840_write(client, 0x8d3, 0x1f); if (state->aud_input == CX25840_AUDIO_SERIAL) { /* Set Path1 to Serial Audio Input */ cx25840_write4(client, 0x8d0, 0x12100101); /* The microcontroller should not be started for the * non-tuner inputs: autodetection is specific for * TV audio. */ } else { /* Set Path1 to Analog Demod Main Channel */ cx25840_write4(client, 0x8d0, 0x7038061f); /* 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 void set_balance(struct i2c_client *client, int balance) { int bal = balance >> 8; if (bal > 0x80) { /* PATH1_BAL_LEFT */ cx25840_and_or(client, 0x8d5, 0x7f, 0x80); /* PATH1_BAL_LEVEL */ cx25840_and_or(client, 0x8d5, ~0x7f, bal & 0x7f); } else { /* PATH1_BAL_LEFT */ cx25840_and_or(client, 0x8d5, 0x7f, 0x00); /* PATH1_BAL_LEVEL */ cx25840_and_or(client, 0x8d5, ~0x7f, 0x80 - bal); } }
void cx25840_audio_set_path(struct i2c_client *client) { struct cx25840_state *state = to_state(i2c_get_clientdata(client)); if (!is_cx2583x(state)) { /* assert soft reset */ cx25840_and_or(client, 0x810, ~0x1, 0x01); /* stop microcontroller */ cx25840_and_or(client, 0x803, ~0x10, 0); /* Mute everything to prevent the PFFT! */ cx25840_write(client, 0x8d3, 0x1f); if (state->aud_input == CX25840_AUDIO_SERIAL) { /* Set Path1 to Serial Audio Input */ cx25840_write4(client, 0x8d0, 0x01011012); /* The microcontroller should not be started for the * non-tuner inputs: autodetection is specific for * TV audio. */ } else { /* Set Path1 to Analog Demod Main Channel */ cx25840_write4(client, 0x8d0, 0x1f063870); } } set_audclk_freq(client, state->audclk_freq); if (!is_cx2583x(state)) { 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); } /* deassert soft reset */ cx25840_and_or(client, 0x810, ~0x1, 0x00); /* Ensure the controller is running when we exit */ if (is_cx2388x(state) || is_cx231xx(state)) cx25840_and_or(client, 0x803, ~0x10, 0x10); } }
int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq) { struct i2c_client *client = v4l2_get_subdevdata(sd); struct cx25840_state *state = to_state(sd); int retval; if (!state->is_cx25836) cx25840_and_or(client, 0x810, ~0x1, 1); if (state->aud_input != CX25840_AUDIO_SERIAL) { cx25840_and_or(client, 0x803, ~0x10, 0); cx25840_write(client, 0x8d3, 0x1f); } retval = set_audclk_freq(client, freq); if (state->aud_input != CX25840_AUDIO_SERIAL) cx25840_and_or(client, 0x803, ~0x10, 0x10); if (!state->is_cx25836) cx25840_and_or(client, 0x810, ~0x1, 0); return retval; }
static void set_mute(struct i2c_client *client, int mute) { struct cx25840_state *state = i2c_get_clientdata(client); if (state->aud_input != CX25840_AUDIO_SERIAL) { /* Must turn off microcontroller in order to mute sound. * Not sure if this is the best method, but it does work. * If the microcontroller is running, then it will undo any * changes to the mute register. */ if (mute) { /* disable microcontroller */ cx25840_and_or(client, 0x803, ~0x10, 0x00); cx25840_write(client, 0x8d3, 0x1f); } else { /* enable microcontroller */ cx25840_and_or(client, 0x803, ~0x10, 0x10); } } else { /* SRC1_MUTE_EN */ cx25840_and_or(client, 0x8d3, ~0x2, mute ? 0x02 : 0x00); } }
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->is_cx25836) cx25840_and_or(client, 0x810, ~0x1, 1); if (state->aud_input != CX25840_AUDIO_SERIAL) { cx25840_and_or(client, 0x803, ~0x10, 0); cx25840_write(client, 0x8d3, 0x1f); } retval = set_audclk_freq(client, *(u32 *)arg); if (state->aud_input != CX25840_AUDIO_SERIAL) { cx25840_and_or(client, 0x803, ~0x10, 0x10); } if (!state->is_cx25836) cx25840_and_or(client, 0x810, ~0x1, 0); return retval; case VIDIOC_G_CTRL: switch (ctrl->id) { case V4L2_CID_AUDIO_VOLUME: ctrl->value = get_volume(client); break; case V4L2_CID_AUDIO_BASS: ctrl->value = get_bass(client); break; case V4L2_CID_AUDIO_TREBLE: ctrl->value = get_treble(client); break; case V4L2_CID_AUDIO_BALANCE: ctrl->value = get_balance(client); break; case V4L2_CID_AUDIO_MUTE: ctrl->value = get_mute(client); break; default: return -EINVAL; } break; case VIDIOC_S_CTRL: switch (ctrl->id) { case V4L2_CID_AUDIO_VOLUME: set_volume(client, ctrl->value); break; case V4L2_CID_AUDIO_BASS: set_bass(client, ctrl->value); break; case V4L2_CID_AUDIO_TREBLE: set_treble(client, ctrl->value); break; case V4L2_CID_AUDIO_BALANCE: set_balance(client, ctrl->value); break; case V4L2_CID_AUDIO_MUTE: set_mute(client, ctrl->value); break; default: return -EINVAL; } break; default: return -EINVAL; } return 0; }
static void set_treble(struct i2c_client *client, int treble) { /* PATH1_EQ_TREBLE_VOL */ cx25840_and_or(client, 0x8db, ~0x3f, 48 - (treble * 48 / 0xffff)); }
static void set_bass(struct i2c_client *client, int bass) { /* PATH1_EQ_BASS_VOL */ cx25840_and_or(client, 0x8d9, ~0x3f, 48 - (bass * 48 / 0xffff)); }
static int set_audclk_freq(struct i2c_client *client, u32 freq) { struct cx25840_state *state = i2c_get_clientdata(client); 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); if (state->aud_input != CX25840_AUDIO_SERIAL) { switch (freq) { case 32000: /* VID_PLL and AUX_PLL */ cx25840_write4(client, 0x108, 0x0f040610); /* AUX_PLL_FRAC */ cx25840_write4(client, 0x110, 0xee39bb01); /* src3/4/6_ctl = 0x0801f77f */ cx25840_write4(client, 0x900, 0x7ff70108); cx25840_write4(client, 0x904, 0x7ff70108); cx25840_write4(client, 0x90c, 0x7ff70108); break; case 44100: /* VID_PLL and AUX_PLL */ cx25840_write4(client, 0x108, 0x0f040910); /* AUX_PLL_FRAC */ cx25840_write4(client, 0x110, 0xd66bec00); /* src3/4/6_ctl = 0x08016d59 */ cx25840_write4(client, 0x900, 0x596d0108); cx25840_write4(client, 0x904, 0x596d0108); cx25840_write4(client, 0x90c, 0x596d0108); break; case 48000: /* VID_PLL and AUX_PLL */ cx25840_write4(client, 0x108, 0x0f040a10); /* AUX_PLL_FRAC */ cx25840_write4(client, 0x110, 0xe5d69800); /* src3/4/6_ctl = 0x08014faa */ cx25840_write4(client, 0x900, 0xaa4f0108); cx25840_write4(client, 0x904, 0xaa4f0108); cx25840_write4(client, 0x90c, 0xaa4f0108); break; } } else { switch (freq) { case 32000: /* VID_PLL and AUX_PLL */ cx25840_write4(client, 0x108, 0x0f04081e); /* AUX_PLL_FRAC */ cx25840_write4(client, 0x110, 0x69082a01); /* src1_ctl = 0x08010000 */ cx25840_write4(client, 0x8f8, 0x00000108); /* src3/4/6_ctl = 0x08020000 */ cx25840_write4(client, 0x900, 0x00000208); cx25840_write4(client, 0x904, 0x00000208); cx25840_write4(client, 0x90c, 0x00000208); /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x14 */ cx25840_write(client, 0x127, 0x54); break; case 44100: /* VID_PLL and AUX_PLL */ cx25840_write4(client, 0x108, 0x0f040918); /* AUX_PLL_FRAC */ cx25840_write4(client, 0x110, 0xd66bec00); /* src1_ctl = 0x08010000 */ cx25840_write4(client, 0x8f8, 0xcd600108); /* src3/4/6_ctl = 0x08020000 */ cx25840_write4(client, 0x900, 0x85730108); cx25840_write4(client, 0x904, 0x85730108); cx25840_write4(client, 0x90c, 0x85730108); break; case 48000: /* VID_PLL and AUX_PLL */ cx25840_write4(client, 0x108, 0x0f040a18); /* AUX_PLL_FRAC */ cx25840_write4(client, 0x110, 0xe5d69800); /* src1_ctl = 0x08010000 */ cx25840_write4(client, 0x8f8, 0x00800108); /* src3/4/6_ctl = 0x08020000 */ cx25840_write4(client, 0x900, 0x55550108); cx25840_write4(client, 0x904, 0x55550108); cx25840_write4(client, 0x90c, 0x55550108); break; } } /* deassert soft reset */ cx25840_and_or(client, 0x810, ~0x1, 0x00); state->audclk_freq = freq; return 0; }